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

can not use Action type with async handler #2301

Open
basaran opened this issue Feb 25, 2024 · 1 comment
Open

can not use Action type with async handler #2301

basaran opened this issue Feb 25, 2024 · 1 comment

Comments

@basaran
Copy link

basaran commented Feb 25, 2024

Describe the bug

I have an async fuction that I use in my use directive, but LSP gives me a type error although the code works as intended.
I use async in my handler because I use dynamic imports in my action.

export async function doSomething(
    node: HTMLElement,
    jsonData: JsonData,
): Promise<ActionReturn>

Argument of type 'Promise<ActionReturn<undefined, Record<never, any>>> is not assignable to parameter of type '__sveltets_2_SvelteActionReturnType'.

If I use:

export async function doSomething(
    node: HTMLElement,
    jsonData: JsonData,
): ActionReturn

The type error disappears from the parent component, but I get a "you must use Promise.." in my handler.

Reproduction

The type for Action is here:
https://github.com/sveltejs/svelte/blob/83b92372c22da2f8a0f8350fa856087a7170275b/packages/svelte/types/index.d.ts#L434

Logs

No response

System Info

System:
    OS: Linux 6.6 Manjaro Linux
    CPU: (3) x64 Intel(R) Core(TM) i5-8365U CPU @ 1.60GHz
    Memory: 7.05 GB / 15.40 GB
    Container: Yes
    Shell: 5.9 - /usr/bin/zsh
  Binaries:
    Node: 21.5.0 - /usr/bin/node
    npm: 10.3.0 - /usr/bin/npm
    pnpm: 8.14.1 - /usr/bin/pnpm

Severity

annoyance

@dummdidumm dummdidumm transferred this issue from sveltejs/svelte Feb 25, 2024
@basaran
Copy link
Author

basaran commented Feb 25, 2024

I was informed on the discord by MotionlessTrain that the actions are supposed to sync, but instead suggested to use promises. On another site I also found example of using an async function inside the action handler, and assigning it to an event. Sorry for the inconvenience, I will close the issue.

Perhaps, the documentation could be updated to make this requirement stated for other users?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant