noUncheckedIndexedAccess
The compiler option that adds undefined to the type of every array index or dictionary lookup, because the entry might not exist.
In more detail
With it, names[0] on a string array has type string | undefined, so you must check before using it. It pairs with index signatures, where any key may be missing. It is not part of strict and must be turned on separately.
Related terms
- index signature — A type rule such as { [key: string]: string } for objects whose property names are not known in advance.
- strict (compiler option) — The strict compiler option, which turns on a family of stronger checks such as strictNullChecks and noImplicitAny in one setting.
- undefined — The JavaScript value meaning not set: a variable with no value yet, a missing property or a function that returned nothing.
Taught in
- tsconfig.json: target, lib, strict And NodeNext — Production TypeScript
- Optional Properties, Readonly And Index Signatures — Production TypeScript