TypeScript 定时器类型异常 不能将类型“Timeout”分配给类型“number” Type 'Timeout' is not assignable to type 'number'.

问题

不能将类型“Timeout”分配给类型“number”
Type 'Timeout' is not assignable to type 'number'.

解决方案

设置类型为NodeJS.Timeout
清除时使用delete ref.timer + clearTimeout

export type TimerType = NodeJS.Timeout
current.timer = setTimeout(() => {
    delete current.timer
},timeout)
posted @ 2022-06-21 00:05  IslandZzzz  阅读(3655)  评论(0编辑  收藏  举报