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 ActionData is unknown in TypeScript, but correct in JavaScript in VSCode #6668

Closed
jeppech opened this issue Sep 8, 2022 · 2 comments
Closed

Comments

@jeppech
Copy link

jeppech commented Sep 8, 2022

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

  • git clone https://github.com/jeppech/svelte-action-data-ts-bug
  • Go to the js folder, install dependencies and run the dev script. cd js && pnpm install && pnpm run dev
  • Go to the ts folder, install dependencies and run the dev script. cd ts && pnpm install && pnpm run dev

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

@aloker
Copy link
Contributor

aloker commented Sep 8, 2022

I'm seeing this, too, but the issue is probably a duplicate of #6631, right?

@jeppech
Copy link
Author

jeppech commented Sep 8, 2022

I'm seeing this, too, but the issue is probably a duplicate of #6631, right?

You're right, I did not spot that when searching the issue list. I'll close this. Thanks! 😀

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

3 participants