typescript - 为什么当我将数字视为数组时没有 Typescript 编译错误?
问题描述
我想知道为什么当我做这样的公然错误时没有错误:
const test : number = 123;
const test2 = test[3];
这是我正在使用的 tsconfig:
{
"compilerOptions": {
"module": "commonjs",
"declaration": true,
"removeComments": true,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"allowSyntheticDefaultImports": true,
"target": "es2017",
"sourceMap": true,
"outDir": "./dist",
"baseUrl": "./",
"incremental": true
}
}
解决方案
您需要添加
"strict": true
到你的 tsconfig。
推荐阅读
- c++ - 在 C++ 中重写 const 成员函数
- pandas - 熊猫:如果另一列的字符串以(“A”,“B”,“C”)开头,则用(1,2,3)创建一列
- c# - 只有单元测试可观察行为,而不是系统要求?
- ios - IMA iOS DAI 广告在来自后台时未恢复
- swift - 在 Swift 中规范化(组合和分解)utf8 字符串
- javascript - 如何使用 JQuery 添加工具提示?
- javascript - 配置一个js库告诉webpack使用ES6模块dist文件
- javascript - prerender 的 NoState Prefetch 是什么?
- android - 如何在嵌套 Recyler 视图中使用 Kotlin 高阶函数
- swift - 如何将文本文件保存到云文件夹(MacOS Swift 应用程序)?