2

There is a sample of setTimeout using in angular and typescript:

let timer: number = setTimeout(() => {
}, 2000);

On compilation I get this message:

error TS2322: Type 'Timeout' is not assignable to type 'number'.

Ho do I use setTimeout with typescript?

5
  • 2
    let timer: Timeout = ... maybe? Commented Jul 21, 2021 at 13:17
  • @mr_blond, May you please add the content of the tsconfig.json file? Commented Jul 21, 2021 at 13:20
  • stackoverflow.com/questions/51040703/… Commented Jul 21, 2021 at 13:26
  • @Calculuswhiz in both nodejs and browser. Commented Jul 21, 2021 at 13:29
  • BTW, I suggest use timer rxjs operator Commented Jul 21, 2021 at 18:21

1 Answer 1

1

Just use like this

let timer = setTimeout(() => {
}, 2000);
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.