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

Type Inference Issue in Svelte 5 #12617

Open
matheustavarestrindade opened this issue Aug 26, 2024 · 1 comment
Open

Type Inference Issue in Svelte 5 #12617

matheustavarestrindade opened this issue Aug 26, 2024 · 1 comment

Comments

@matheustavarestrindade
Copy link

Describe the bug

Description: In Svelte 5, I've encountered an issue with type inference when using the load function in +page.server.ts.

When I pass a direct object as an argument to the load function, the type inference fails on the corresponding +page.svelte file. However, if I encapsulate the object inside another object (e.g., { obj }), the type inference works correctly.

Steps to Reproduce:

Create a +page.server.ts file.
Implement a load function that returns a direct object with the type or null, e.g., return { key: value }.]

Attempt to use the returned data in the +page.svelte file and observe the lack of type inference.
Modify the load function to return an encapsulated object, e.g., return { obj: { key: value } }.
Observe that the type inference now works correctly.

Expected Behavior: The type inference should work correctly even when passing a direct object in the load function.

Actual Behavior: Type inference fails when passing a direct object, requiring encapsulation to work properly.

Reproduction

Direct object:

image

image

With encapsulation:

image

image

Logs

No response

System Info

System:
    OS: Windows 10 10.0.19045
    CPU: (24) x64 AMD Ryzen 9 5900X 12-Core Processor
    Memory: 21.66 GB / 63.91 GB
  Binaries:
    Node: 20.12.1 - C:\Program Files\nodejs\node.EXE
    npm: 10.8.2 - C:\Program Files\nodejs\npm.CMD
  Browsers:
    Edge: Chromium (127.0.2651.74)
    Internet Explorer: 11.0.19041.4355
  npmPackages:
    @sveltejs/adapter-auto: ^3.0.0 => 3.2.4
    @sveltejs/kit: ^2.0.0 => 2.5.24
    @sveltejs/vite-plugin-svelte: ^4.0.0-next.6 => 4.0.0-next.6
    svelte: ^5.0.0-next.238 => 5.0.0-next.238
    vite: ^5.0.3 => 5.4.2

Severity

annoyance

Additional Information

No response

@jasonlyu123
Copy link
Member

This matches the actual runtime behavior. If you returned null or undefined the data props is an empty object.

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

10 participants
@benmccann @dummdidumm @jasonlyu123 @matheustavarestrindade and others