typescript - 打字稿没有抱怨关于没有在构造函数中声明类型
问题描述
我是打字稿的新手,我期待打字稿会因为没有为我的构造函数声明类型而引发错误,但不幸的是我不是......
所以我很好奇为什么我没有收到错误。
这就是我正在做的
export interface BaseConfig {
app: express.Application,
routePermission: number,
context: any
}
export class BaseConfig implements BaseConfig {
constructor(
context,
authentication = false,
authenticatedRoute = USER_TYPE.LOGGED_IN_NORMAL_USER
) {
//intitalize Express App
this.routePermission = authenticatedRoute
this.context = context
this.app = express()
这是我的tsconfig
{
"compilerOptions": {
"moduleResolution": "node",
"experimentalDecorators": true,
"module": "commonjs",
"noImplicitReturns": true,
"noUnusedLocals": true,
"outDir": "lib",
"sourceMap": true,
"strict": true,
"target": "es2017",
"resolveJsonModule": true,
"esModuleInterop": true,
"noImplicitAny": false
},
"compileOnSave": true,
"include": [
"src"
],
"exclude": ["node_modules"]
}
解决方案
noImplicitAny
应该设置为真。当为 false 时,意味着隐式 any 被接受,并且没有类型声明的变量因此隐式地具有 type any
。
推荐阅读
- angular - Angular 7 打字稿。创建可在 Chrome 控制台中直接访问的变量
- django - 在 VSCode 中保存 Django 项目
- batch-file - 批量 if/else 语句
- forms - Symfony twig 从集合对象中获取数据值
- javascript - 我能以某种方式创建一个看起来像 .toUpperCase() 的函数吗?
- python - 如何在 Python 中更改继承方法的文档字符串?
- javascript - 时间戳,剥离时间
- adodb - 将 ADODB 记录集复制到表中而不循环
- c# - asp.net:代码工作>添加了参考>获取错误>删除参考但仍然发生错误
- iis - IIS 即时弹出窗口