If you have not set strict: true
or noImplicitAny: true
in your tsconfig.json
, it is completely normal for the index in bracket notation to be treated as any
.
For more details on this issue, you can refer to:
https://github.com/microsoft/TypeScript/issues/7660
You can view the outcome before and after enabling noImplicitAny
in this playground:
- Without
noImplicitAny
, no error will occur.
- With
noImplicitAny
, an error will be prompted regarding map["xx"]
P.S.
You have the option to use either noImplicitAny: true
or strict: true
, with strict
mode encompassing noImplicitAny
and 6 additional implicit checks. Refer to the typescript documentation for further information.
While strict mode is not the default setting due to migration concerns and legacy issues, the TypeScript team highly recommends enabling strict: true
in their thoughts on using strict mode in TypeScript.
Indeed, by default, TypeScript's tsconfig does not enable strict mode. However, whenever possible, our team encourages users to transition towards incorporating strict mode into their configurations.