Default
false
Description
TypeScript supports index signatures. These signatures are a way to signal to the type system that users can access arbitrarily-named properties:
When the --noUncheckedIndexAccess
flag is used, every property access
(like foo.bar
) or indexed access (like foo["bar"]
) that ends up
resolving to an index signature is considered potentially undefined. Ie:
opts.yadda
will have the type string | number | undefined
as opposed
to just string | number
. If you need to access that property, you’ll
either have to check for its existence first or use a non-null assertion
operator (the postfix !
character):
One consequence of using --noUncheckedIndexedAccess
is that indexing
into an array is also more strictly checked,
even in a bounds-checked loop:
If you don’t need the indexes, you can iterate over individual elements by using a for-of loop or a forEach call:
This flag can be handy for catching out-of-bounds errors, but it might
be noisy for a lot of code, so it is not automatically enabled by the
--strict
flag. More information can be found in the PR1.