Skip to content

setTimeout incorrect typings browser #32133

Closed
@GoGoris

Description

@GoGoris

TypeScript Version: 3.4.5

Search Terms: setTimeout

Code

const timeout: number = setTimeout(() => console.log('anything'), 300);

Expected behavior:

It compiles correctly

Actual behavior:

Type 'Timeout' is not assignable to type 'number'.

1 const timeout: number = setTimeout(() => console.log('anything'), 300);
        ~~~~~~~


Found 1 error.

Playground Link:

Not reproducable in playground

Related Issues:

Possibly #19635, but this issue seems to be outdated because now the declaration of setTimeout looks like:

type TimerHandler = string | Function;
setTimeout(handler: TimerHandler, timeout?: number, ...arguments: any[]): number;

https://stackoverflow.com/q/45802988

Metadata

Metadata

Assignees

No one assigned

    Labels

    QuestionAn issue which isn't directly actionable in code

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions