Skip to content

Svelte 5: Runes $effect does not allow async function #10959

@Dudek-AMS

Description

@Dudek-AMS

Describe the bug

Typescript throws error when using an async function in $effect since it expects a void function

Reproduction

   $effect(async () => {
        let res = await fetch(location.href, {
            method: 'POST',
            headers: {
                'content-type': 'application/json'
            },
            body: JSON.stringify({action: 'validatemail', email})
        });
        error = await res.json();
    });

Logs

Svelte: Argument of type () => Promise<void> is not assignable to parameter of type () => void | (() => void)
Type Promise<void> is not assignable to type void | (() => void)

System Info

@next.85

Severity

annoyance

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions