Skip to content

Type ActionData is unknown in TypeScript, but correct in JavaScript in VSCode #6668

@jeppech

Description

@jeppech

Describe the bug

It seems that there's a bug, when inferring types from the new actions export (recently merged #6469), in the +page.server.ts files.

I'm using the Svelte for VS Code v105.22.1 extension.

In short, the ActionData type is not inferred correctly in TypeScript projects. But it is in JavaScript projects.

// +page.server.svelte
import type { Actions } from './$types'

export const actions: Actions = {
  default: ({ request }) => {
    return {
      horse: true
    }
  }
}
// +page.svelte
<script lang="ts">
  import type { PageData, ActionData } from './$types'

  export let data: PageData

  // ActionData is of unknown type
  export let form: ActionData
</script>

Reproduction

The issue can be tested with this project https://github.com/jeppech/svelte-action-data-ts-bug

Open the js and ts folder, in their own instance of VSCode.

In the JavaScript project src/routes/+page.svelte: The ActionData-type has a horse property, which is correctly inferred from the +page.server.js file

In the TypeScript project src/routes/+page.svelte: The ActionData-type is unknown, so it's not being inferred correctly from the +page.server.ts file

Logs

No response

System Info

❯ pnpx envinfo --system --binaries --browsers --npmPackages "{svelte,@sveltejs/*,vite}"
.../../.node/pnpm/store/v3/tmp/dlx-65331 |   +1 +
Packages are hard linked from the content-addressable store to the virtual store.
  Content-addressable store is at: /Users/jc/.node/pnpm/store/v3
  Virtual store is at:             ../../../.node/pnpm/store/v3/tmp/dlx-65331/node_modules/.pnpm
.../../.node/pnpm/store/v3/tmp/dlx-65331 | Progress: resolved 1, reused 0, downloaded 1, added 1, done

  System:
    OS: macOS 12.4
    CPU: (8) arm64 Apple M1 Pro
    Memory: 1.13 GB / 16.00 GB
    Shell: 5.8.1 - /bin/zsh
  Binaries:
    Node: 16.17.0 - ~/Library/pnpm/node
    npm: 8.15.0 - ~/Library/pnpm/npm
  Browsers:
    Brave Browser: 105.1.43.89
    Safari: 15.5
  npmPackages:
    @sveltejs/adapter-auto: next => 1.0.0-next.71
    @sveltejs/kit: next => 1.0.0-next.477
    svelte: ^3.44.0 => 3.50.0
    vite: ^3.1.0 => 3.1.0

Severity

blocking an upgrade

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