Skip to content

svelte-language-server fails to infer function type for load method in +server.ts page #1971

@flmng0

Description

@flmng0

Describe the bug

In +page.ts and +page.server.ts files, the type for load events does not get inferred.

According to https://svelte.dev/blog/zero-config-type-safety , I should not need to explicitly type the parameter of the exported load function in said files.

Reproduction

Create any API route, e.g src/routes/+page.server.ts, and add a load function to the file, like below:

export async function load(event) { // ERROR: Parameter 'event' implicitly has an 'any' type.
  const { fetch } = event;

  const response = await fetch(/* ... */);

  return await response.json();
}

Expected behaviour

The type of the event parameter in the function below should be inferred.

export async function load(event) {
  const { fetch } = event; // <-- type of fetch should be automatically inferred.

  // ...
}

System Info

  • OS: Fedora 37
  • IDE: NeoVim using Mason and svelte-language-server@0.15.8

Which package is the issue about?

svelte-language-server

Additional Information, eg. Screenshots

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions