fix: update onMount type to allow async to return any (#8714)

---------

Co-authored-by: Simon H <5968653+dummdidumm@users.noreply.github.com>
pull/8762/head
GrygrFlzr 1 year ago committed by GitHub
parent 0724261b4d
commit 54f72f4545
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -36,9 +36,7 @@ export function beforeUpdate(fn) {
*
* https://svelte.dev/docs#run-time-svelte-onmount
* @template T
* @param {() => T extends Promise<() => any>
* ? "Returning a function asynchronously from onMount won't call that function on destroy"
* : T} fn
* @param {() => import('./private.js').NotFunction<T> | Promise<import('./private.js').NotFunction<T>> | (() => any)} fn
* @returns {void}
*/
export function onMount(fn) {

@ -123,3 +123,8 @@ export interface Task {
abort(): void;
promise: Promise<void>;
}
/**
* Anything except a function
*/
type NotFunction<T> = T extends Function ? never : T;

@ -51,8 +51,15 @@ onMount(async () => {
};
});
// @ts-expect-error async and return any
// async and return any
onMount(async () => {
const a: any = null as any;
return a;
});
// async and return function casted to any
// can't really catch this without also catching above
onMount(async () => {
const a: any = (() => {}) as any;
return a;
});

Loading…
Cancel
Save