Skip to content

Svelte 5: $effect async callback type missing TypeScript #9946

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

Closed
codeit-ninja opened this issue Dec 17, 2023 · 2 comments
Closed

Svelte 5: $effect async callback type missing TypeScript #9946

codeit-ninja opened this issue Dec 17, 2023 · 2 comments

Comments

@codeit-ninja
Copy link

Describe the bug

When passing a async callback in $effect, causes error.

Example:

$effect( async () => {
   // ... code
})

image

Reproduction

let count = $state(0);

$effect( async () => {
	const request = await fetch('https://dummyjson.com/products/1')
	const json = await request.json()
		
	console.log(json)
})

### Logs

_No response_

### System Info

```shell
System:
    OS: Linux 5.15 Ubuntu 22.04.2 LTS 22.04.2 LTS (Jammy Jellyfish)
    CPU: (16) x64 AMD Ryzen 7 5800X3D 8-Core Processor
    Memory: 10.00 GB / 15.58 GB
    Container: Yes
    Shell: 5.1.16 - /bin/bash
  Binaries:
    Node: 20.9.0 - ~/.volta/tools/image/node/20.9.0/bin/node
    Yarn: 4.0.1 - ~/.volta/tools/image/yarn/4.0.1/bin/yarn
    npm: 10.1.0 - ~/.volta/tools/image/node/20.9.0/bin/npm
    bun: 1.0.18 - ~/.bun/bin/bun
  Browsers:
    Chrome: 117.0.5938.88
  npmPackages:
    svelte: 5.0.0-next.25

Severity

annoyance

@PuruVJ
Copy link
Collaborator

PuruVJ commented Dec 17, 2023

AFAIK, $effect doesn't accept async function as callback. Solution is to declare an async function inside the $effect callback and call that function

@Conduitry
Copy link
Member

Duplicate of #9520. It is intentional that the types do not admit an asynchronous function.

@Conduitry Conduitry closed this as not planned Won't fix, can't repro, duplicate, stale Dec 17, 2023
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

3 participants