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

Time:09-23

I'm wondering why there's no error when I do something blatantly wrong like this:

const test : number = 123;
const test2 = test[3];

This is the tsconfig I'm using:

{
  "compilerOptions": {
    "module": "commonjs",
    "declaration": true,
    "removeComments": true,
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "allowSyntheticDefaultImports": true,
    "target": "es2017",
    "sourceMap": true,
    "outDir": "./dist",
    "baseUrl": "./",
    "incremental": true
  }
}

CodePudding user response:

You need to add

"strict": true

to your tsconfig.

  • Related