当前位置:网站首页>Typescript definition type: type 'timeout' cannot be assigned to type 'number';
Typescript definition type: type 'timeout' cannot be assigned to type 'number';
2022-06-12 20:30:00 【wendyTan10】
Typescript to setTimeout The return value of is defined as number And assign a value to , The following errors will be reported :
error message : You can't type “Timeout” Assign to type “number”
;
Locate by clicking , Find out setTimeout Under current project Node.js Interface definition file under :
@types/node index.d.ts, The current definition here is Timerout
type
declare function setTimeout(callback: (...args: any[]) => void, ms: number, ...args: any[]): NodeJS.Timer;
And the use here :clearTimeout
The required parameter is Number
type
So what we have to do here is :
// Method 1 :
// Defined NodeJs.Timeout The type of
let timer: null| NodeJS.Timeout = null;
timer = setTimeout(() => {
}, 1000);
// When it's cleared , Convert to Number type
clearTimeout(Number(timer));
// Method 2 :
// Can be used directly window.setTimeout() Methods , What is returned is directly Nummber type
let timer: number;
timer = window.setTimeout(() => {
}, 1000);
clearTimeout(timer);
边栏推荐
- Bsn-ddc basic network introduction, technical features, unique advantages, application scenarios and platform access
- Operating instructions for installing mysql5.7 in centos7
- Introduction to system mode development of rouya wechat mall
- Illustrator tutorial, how to recolor artwork in illustrator?
- [generation confrontation network learning III] reading notes of Bigan paper and its principle understanding
- Experience Technology Department of ant group launched the 2023rd school recruitment
- Alipay payment Episode 12: Crazy God and Feige Alipay payment configuration code (free resources, no thanks for taking them away)
- Viewpoint sharing | Li Wei, an expert of Gewu titanium intelligent technology products: underlying logic and scenario practice of unstructured data platform
- WordPress optimization tutorial makes WordPress open faster
- Halcon angle and radian interchange
猜你喜欢
Properties to YML
Fcpx tutorial, how to export video graphics and text in Final Cut Pro?
Index optimization principle
Since using low code development, the development efficiency has been increased by 10 times
Event distribution mechanism of view
Niuke net: somme des trois nombres
How mysterious is "PIP not an internal or external command, nor a runnable program or batch file"
sklearn中随机森林RandomForestClassifier的参数含义
2022年春招,测试工程师全套面试攻略,一篇吃透全部技术栈(全是干货)
逐向双碳:东数西算中的绿色需求与竞争焦点
随机推荐
WordPress optimization tutorial makes WordPress open faster
登錄mysql
6 R factor and judgment Na
20 shortcut keys for vs code!
The joint empowerment plan of Baidu PaddlePaddle large enterprise open innovation center was launched! Help Pudong to upgrade its industry intelligently
Handwritten promise
MySQL installation and Application
2 R programming
Halcon angle and radian interchange
The joint empowerment plan of Baidu PaddlePaddle large enterprise open innovation center was launched! Help Pudong to upgrade its industry intelligently
Restful API 接口规范
Compilation of programs
P5076 【深基16.例7】普通二叉树(简化版)
Dynamic memory management
测试人如何规划自己的未来?才能实现入行2年达到25k?
How to determine fragment restored from Backstack
Transaction code qs28 of SAP QM preliminary level
Go memory escape analysis
JSP中的监听器
At the beginning of SAP QM, assign sampling strategy for quantitative characteristics