Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/438.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 使用setTimeout生成类型错误_Javascript_Ecmascript 6 - Fatal编程技术网

Javascript 使用setTimeout生成类型错误

Javascript 使用setTimeout生成类型错误,javascript,ecmascript-6,Javascript,Ecmascript 6,我想使用setTimeout延迟加载,我有一个变量语句,它是全局的。但是当我在输入标签中输入内容时,它会生成一个TypeError; 我不知道为什么 代码如下: var searchInvoiceTimer = null; clearTimeout(searchInvoiceTimer); searchInvoiceTimer = setTimeout(function(){ console.log(1) },1000) main.js:14 Uncaught TypeError: t

我想使用setTimeout延迟加载,我有一个变量语句,它是全局的。但是当我在输入标签中输入内容时,它会生成一个TypeError; 我不知道为什么

代码如下:

var searchInvoiceTimer = null;
clearTimeout(searchInvoiceTimer);
searchInvoiceTimer = setTimeout(function(){
    console.log(1)
},1000)
main.js:14 Uncaught TypeError: timeout.close is not a function
at exports.clearTimeout.exports.clearInterval (main.js:14)
at index.js:540
at Array.map (<anonymous>)
at App.handleTaskChange (index.js:526)
at onChange (index.js:991)
at Object.executeOnChange (LinkedValueUtils.js:132)
at ReactDOMComponent._handleChange (ReactDOMInput.js:241)
at Object.ReactErrorUtils.invokeGuardedCallback (ReactErrorUtils.js:69)
at executeDispatch (EventPluginUtils.js:85)
at Object.executeDispatchesInOrder (EventPluginUtils.js:108)
错误如下:

var searchInvoiceTimer = null;
clearTimeout(searchInvoiceTimer);
searchInvoiceTimer = setTimeout(function(){
    console.log(1)
},1000)
main.js:14 Uncaught TypeError: timeout.close is not a function
at exports.clearTimeout.exports.clearInterval (main.js:14)
at index.js:540
at Array.map (<anonymous>)
at App.handleTaskChange (index.js:526)
at onChange (index.js:991)
at Object.executeOnChange (LinkedValueUtils.js:132)
at ReactDOMComponent._handleChange (ReactDOMInput.js:241)
at Object.ReactErrorUtils.invokeGuardedCallback (ReactErrorUtils.js:69)
at executeDispatch (EventPluginUtils.js:85)
at Object.executeDispatchesInOrder (EventPluginUtils.js:108)

在代码检查中,必须导入clearTimeout


删除该选项并使用正常的clearTimeout方法。

这可能是因为您的IDE。检查您的代码中是否有以下导入

import { clearInterval } from 'timers';
这是因为某些IDE具有自动导入功能。 如果要禁用此功能,只需在IDE设置中修复即可

"typescript.autoImportSuggestions.enabled": false

干杯

发布更多的代码,特别是全局变量。欢迎使用堆栈溢出!请采取,看看周围,并通过阅读,特别是代码张贴明确不会导致错误列出,必须有更多的,如导入。谢谢你的回答。但原因不是这个,我已经找到了问题。谢谢。我已经知道问题,原因是我导入'导入{clearInterval}来自“计时器”删除后,代码完全正常。