Skip to content

Type Inference Issue in Svelte 5 #12617

@matheustavarestrindade

Description

@matheustavarestrindade

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions