Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Typing of PageData doesn't work with Promise returns from load functions #11065

Closed
bertmad3400 opened this issue Nov 17, 2023 · 2 comments
Closed

Comments

@bertmad3400
Copy link

Describe the bug

Only tested using Typescript

As a convenience, SvelteKit automatically awaits top-level promises in load functions, giving the return of the load functions and the actual data available to the pages a slightly different type-interface. Svelte handles this by using different types for load functions and page data.

Unfortunately, this produces type errors when attempting to strongly type the PageData interface. If the load function returns a promise with a number, the page will only receive the number, and typing the PageData interface with either a promise with a number or just a number will give of an error, either in the load function or in the page.

Reproduction

https://github.com/bertmad3400/sveltekit-issue

Logs

Errors:

If typing without promise:
"Type 'Promise<number>' is not assignable to type 'number'"

If typing with promise:
"Operator '+' cannot be applied to types '2' and 'Promise<number>'"

System Info

System:
    OS: Linux 6.5 Arch Linux
    CPU: (20) x64 12th Gen Intel(R) Core(TM) i7-12700H
    Memory: 11.00 GB / 15.35 GB
    Container: Yes
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 20.8.1 - /usr/bin/node
    npm: 10.2.1 - /usr/bin/npm
  npmPackages:
    @sveltejs/adapter-auto: ^2.0.0 => 2.1.1 
    @sveltejs/kit: ^1.27.4 => 1.27.6 
    svelte: ^4.0.5 => 4.2.4 
    vite: ^4.4.2 => 4.5.0

Severity

serious, but I can work around it

Additional Information

No response

@bertmad3400
Copy link
Author

Is there any update on this, or can I somehow be of any help in solving this? It seems like an issue that would be general, and it's significantly holding our project back

@Conduitry
Copy link
Member

https://kit.svelte.dev/docs/migrating-to-sveltekit-2#top-level-promises-are-no-longer-awaited - This feature was removed in SK 2.0 - #10106 / #11176. I think going back and figuring out a type fix for v1 is going to be a won't-fix, unfortunately.

@Conduitry Conduitry closed this as not planned Won't fix, can't repro, duplicate, stale Jan 31, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants