mirror of https://github.com/sveltejs/svelte
breaking: update onMount type definition to prevent async function return (#8136)
--------- Co-authored-by: Yuichiro Yamashita <xydybaseball@gmail.com> Co-authored-by: Simon H <5968653+dummdidumm@users.noreply.github.com>pull/8515/head
parent
2f423475f7
commit
236ffa833d
@ -0,0 +1,58 @@
|
|||||||
|
import { onMount } from '$runtime/index';
|
||||||
|
|
||||||
|
// sync and no return
|
||||||
|
onMount(() => {
|
||||||
|
console.log('mounted');
|
||||||
|
});
|
||||||
|
|
||||||
|
// sync and return value
|
||||||
|
onMount(() => {
|
||||||
|
return 'done';
|
||||||
|
});
|
||||||
|
|
||||||
|
// sync and return sync
|
||||||
|
onMount(() => {
|
||||||
|
return () => {
|
||||||
|
return 'done';
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
||||||
|
// sync and return async
|
||||||
|
onMount(() => {
|
||||||
|
return async () => {
|
||||||
|
const res = await fetch('');
|
||||||
|
return res;
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
||||||
|
// async and no return
|
||||||
|
onMount(async () => {
|
||||||
|
await fetch('');
|
||||||
|
});
|
||||||
|
|
||||||
|
// async and return value
|
||||||
|
onMount(async () => {
|
||||||
|
const res = await fetch('');
|
||||||
|
return res;
|
||||||
|
});
|
||||||
|
|
||||||
|
// @ts-expect-error async and return sync
|
||||||
|
onMount(async () => {
|
||||||
|
return () => {
|
||||||
|
return 'done';
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
||||||
|
// @ts-expect-error async and return async
|
||||||
|
onMount(async () => {
|
||||||
|
return async () => {
|
||||||
|
const res = await fetch('');
|
||||||
|
return res;
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
||||||
|
// @ts-expect-error async and return any
|
||||||
|
onMount(async () => {
|
||||||
|
const a: any = null as any;
|
||||||
|
return a;
|
||||||
|
});
|
Loading…
Reference in new issue