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

问题描述

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

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

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

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

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

解决方法

就这样使用

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