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

Missing types from PageServerParentData if parent layout load returns void #7408

Closed
eltigerchino opened this issue Oct 27, 2022 · 0 comments · Fixed by #7425
Closed

Missing types from PageServerParentData if parent layout load returns void #7408

eltigerchino opened this issue Oct 27, 2022 · 0 comments · Fixed by #7425
Labels
bug Something isn't working types / typescript
Milestone

Comments

@eltigerchino
Copy link
Member

eltigerchino commented Oct 27, 2022

Describe the bug

If a layout load function returns void at any part of the function, the types for parent() in child load functions will be broken.

Reproduction

https://stackblitz.com/github/s3812497/sveltekit-load-types-bug?file=src%2Froutes%2Fabout%2F%2Bpage.server.ts

Expected:
src/routes/about/+page.server.ts has types when retrieving data from the parent load function src/routes/+layout.server.ts

Actual:
src/routes/about/+page.server.ts shows an error stating the property does not exist when retrieving the data from parent()
e.g.
Property 'b' does not exist on type 'PageServerParentData'.(2339)

Logs

No response

System Info

System:
    OS: Linux 5.0 undefined
    CPU: (8) x64 Intel(R) Core(TM) i9-9880H CPU @ 2.30GHz
    Memory: 0 Bytes / 0 Bytes
    Shell: 1.0 - /bin/jsh
  Binaries:
    Node: 16.14.2 - /usr/local/bin/node
    Yarn: 1.22.19 - /usr/local/bin/yarn
    npm: 7.17.0 - /usr/local/bin/npm
  npmPackages:
    @sveltejs/adapter-auto: next => 1.0.0-next.84 
    @sveltejs/kit: next => 1.0.0-next.525 
    svelte: ^3.44.0 => 3.52.0 
    vite: ^3.1.0 => 3.2.0

Severity

annoyance

Additional Information

A workaround is to avoid returning void in the parent load function and return an empty object instead.

@benmccann benmccann added the bug Something isn't working label Oct 27, 2022
@benmccann benmccann added this to the 1.0 milestone Oct 27, 2022
dummdidumm added a commit that referenced this issue Oct 28, 2022
… values

Fixes #7408

Also reworking write_types tests to type-check the outcome, not compare the generated code
Rich-Harris pushed a commit that referenced this issue Oct 28, 2022
… values (#7425)

* [fix] better type generation for load functions with different return values

Fixes #7408

Also reworking write_types tests to type-check the outcome, not compare the generated code

* explanation comment

* fix excludes
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working types / typescript
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants