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

@ -123,3 +123,8 @@ export interface Task {
abort(): void; abort(): void;
promise: Promise<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 () => { onMount(async () => {
const a: any = null as any; const a: any = null as any;
return a; 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