首页 > 解决方案 > 为什么当我将数字视为数组时没有 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
  }
}

标签: typescriptcompiler-errors

解决方案


您需要添加

"strict": true

到你的 tsconfig。


推荐阅读