Skip to content

watchEffect typing does not support async callback #14249

@mitar

Description

@mitar

Vue version

3.5.26

Link to minimal reproduction

export type OnCleanup = (cleanupFn: () => void) => void

Steps to reproduce

Observe the type defined on OnCleanup which is used by:

export type WatchEffect = (onCleanup: OnCleanup) => void

Observe that the callback cannot return a promise, so async functions are not allowed by typing.

On the other hand, current documentation does use async and even "async" behavior has an important tip at the end of this section.

What is expected?

Type like:

export type WatchEffect = (onCleanup: OnCleanup) => Promise<void> | void

What is actually happening?

When type checking using eslint, it complains:

Promise returned in function argument where a void return was expected
@typescript-eslint/no-misused-promises

System Info

Any additional comments?

This has been previously reported in vuejs/composition-api#648 and based on recent comments it is still problematic.

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