我如何将 setTimeout 与打字稿一起使用?

时间:2021-07-21 13:16:30

标签: javascript angular typescript timeout

有一个在 angular 和 typescript 中使用的 setTimeout 示例:

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

在编译时,我收到此消息:

<块引用>

错误 TS2322:类型“超时”不能分配给类型“数字”。

我如何将 setTimeout 与 typescript 一起使用?

1 个答案:

答案 0 :(得分:1)

就这样使用

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