Julien
Julien

Reputation: 9442

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

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
  }
}

Upvotes: 0

Views: 24

Answers (1)

Ferruccio
Ferruccio

Reputation: 100758

You need to add

"strict": true

to your tsconfig.

Upvotes: 2

Related Questions