TypeScript / ReactJS / setTimeout:'this'隐式地具有'any'类型,因为它没有类型注释。

里昂·加班

在我的NextJS / React打字稿应用程序中,我正在使用setTimeout。

React应用程序中存在一个错误,导致setTimeout立即被调用,然后我在这里的答案中找到了解决方法:ReactJS:setTimeout()不起作用?

下面是我的代码,但我发现在以下打字稿错误thisthis.resetNotification

任何'this'隐式地具有'any'类型,因为它没有类型批注。ts(2683)Board.tsx(158,7):此容器遮盖了'this'的外部值。

@bind
resetNotification(): any {
  console.log('resetNotification...');
  this.setState({ notificationClass: 'spin-in-notification' });
  this.props.setNotification('', false);
}

@bind
private handleNotificationClick() {
  this.setState({ notificationClass: 'slide-out-bck-top' });

  setTimeout(
    function() {
      this.resetNotification();
    }
    .bind(this),
    500
  );
}

在此处输入图片说明

乔迪·卡斯蒂略

使用setTimeout上的箭头功能针对此日期的父母道具进行操作

setTimeout(
  () => {
  this.resetNotification();
  }......

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

TypeScript:'this' 隐式具有类型 'any',因为它没有类型注释

React Typescript:元素隐式地具有“ any”类型,因为类型没有索引签名

D3.js:'this' 隐式具有类型 'any',因为它没有类型注释

TypeScript TS7015:元素隐式地具有“ any”类型,因为索引表达式不是“ number”类型

'this' 隐式具有类型 'any',因为它没有类型注释。在函数上调用绑定时

TS2683:“ this”隐式具有类型“ any”,因为它没有使用“ apply”进行类型注释

Typescript-React State:元素隐式具有“ any”类型,因为类型“ State”没有索引签名

在打字稿中调用rest API时,面临错误,因为“'this'隐式具有'any'类型,因为它没有类型注释”

TypeScript-元素隐式地具有“ any”类型,因为类型“ string”的表达式不能用于索引类型

Node + TypeScript:“ this”隐式具有类型“ any”

使用d3.mouse时出现D3打字稿错误:“ this”隐式具有类型“ any”,因为它没有类型注释

rest隐式具有any类型,因为它没有类型注释,并且在其自己的初始化程序中直接或间接引用

Typescript错误:元素隐式具有“ any”类型,因为类型“ string”的表达式不能用于索引类型

TypeScript:隐式具有“ any”类型,因为类型“ string”的表达式不能用于索引类型

TypeScript - 元素隐式具有“any”类型,因为“storyFile”类型的表达式不能用于索引类型“{}”

属性 'fullName' 隐式具有类型 'any',因为它的 set 访问器缺少参数类型注释

元素隐式具有 'any' 类型,因为类型 'typeof globalThis' 没有索引签名

元素隐式具有 'any' 类型,因为类型 '{}' 没有索引签名

Angular - 元素隐式具有“any”类型,因为“AbstractControl”类型没有索引签名

元素隐式地具有“ any”类型,因为类型“ any”的表达式不能用于索引类型

TypeScript + ES6 Map +对象类型的索引签名隐式具有“ any”类型

TypeScript:对象类型的索引签名隐式具有“ any”类型

元素隐式地具有“ any”类型,因为类型为string | 数字不能用于索引类型

元素隐式地具有“ any”类型,因为类型“ string”的表达式不能用于索引类型

map()中的Typescript错误:元素隐式具有“ any”类型,因为类型“ string”的表达式不能用于索引类型

带有React> Element的Typescript隐式具有'any'类型,因为类型'string'的表达式不能用于索引

当Typescript检查经典JS类时,如何解决“'this'隐式具有类型'any'”

Typescript / nodejs:变量在某些位置隐式具有类型“ any”

react / typescript:参数“ props”隐式具有“ any”类型错误