File tree Expand file tree Collapse file tree 3 files changed +14
-4
lines changed Expand file tree Collapse file tree 3 files changed +14
-4
lines changed Original file line number Diff line number Diff line change @@ -36,9 +36,7 @@ export function beforeUpdate(fn) {
36
36
*
37
37
* https://svelte.dev/docs#run-time-svelte-onmount
38
38
* @template T
39
- * @param {() => T extends Promise<() => any>
40
- * ? "Returning a function asynchronously from onMount won't call that function on destroy"
41
- * : T} fn
39
+ * @param {() => import('./private.js').NotFunction<T> | Promise<import('./private.js').NotFunction<T>> | (() => any) } fn
42
40
* @returns {void }
43
41
*/
44
42
export function onMount ( fn ) {
Original file line number Diff line number Diff line change @@ -123,3 +123,8 @@ export interface Task {
123
123
abort ( ) : void ;
124
124
promise : Promise < void > ;
125
125
}
126
+
127
+ /**
128
+ * Anything except a function
129
+ */
130
+ type NotFunction < T > = T extends Function ? never : T ;
Original file line number Diff line number Diff line change @@ -51,8 +51,15 @@ onMount(async () => {
51
51
} ;
52
52
} ) ;
53
53
54
- // @ts -expect-error async and return any
54
+ // async and return any
55
55
onMount ( async ( ) => {
56
56
const a : any = null as any ;
57
57
return a ;
58
58
} ) ;
59
+
60
+ // async and return function casted to any
61
+ // can't really catch this without also catching above
62
+ onMount ( async ( ) => {
63
+ const a : any = ( ( ) => { } ) as any ;
64
+ return a ;
65
+ } ) ;
You can’t perform that action at this time.
0 commit comments