为什么我把一个数字当做一个数组,Typescript编译没有报错?

Why is there no Typescript compile error when I treat a number as an array?

我想知道为什么当我做这样明显错误的事情时没有错误:

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。