javascript - Typescript检查经典JS类时如何解决“'this'隐含类型'any'”
问题描述
我有一些使用经典 JS 类的旧代码,我想对其进行类型检查。例如:
/**
* @constructor
*/
function Test() {
this.x = 1;
}
但是,当我运行tsc --noImplicitThis --noEmit --allowJs --checkJs test.js
输入检查它时,我收到以下错误:
test.js:5:5 - error TS2683: 'this' implicitly has type 'any' because it does not have a type annotation.
5 this.x = 1;
~~~~
通过查看https://github.com/Microsoft/TypeScript/wiki/JsDoc-support-in-JavaScript或仅通过猜测,我无法找到任何类型注释来修复此错误。有办法吗?
解决方案
推荐阅读
- python-2.7 - Extract title from multiple urls in python scrapy
- reactjs - npm create-react-app cannot create an app
- html - How to render math symbols inside code block
- c# - Memory assignment in C# for operator + or ++
- python - Python: Reading binary file with date/time
- numpy - 面对 IndexError:只有整数、切片 (`:`)、省略号 (`...`)、numpy.newaxis (`None`) 和整数或布尔数组是有效的索引
- java - OAuth2Config:IllegalStateException:对于 MAC 签名,您不需要单独指定验证者密钥
- python - 用乌龟画三角形
- mysql - mysql中的正则表达式来回答给定的查询
- reactjs - 开玩笑 - 模拟需要事先配置的节点模块