3 ms·
foo[1] is undefined (literally the undefined symbol), in JavaScript index-out-of-bounds is ok. Although i don’t know if TypeScript asserts that x[i] is T | und
by armchairhacker 5y ago
foo[1] is undefined (literally the undefined symbol), in JavaScript index-out-of-bounds is ok.
Although i don’t know if TypeScript asserts that x[i] is T | undefined if x is T[] and the length is non-trivial. In strict mode this would be really useful as you can just do x[i]!, but it requires you to think a bit about index-out-of-bounds or at least throw on the undefined case.
- matt_kantor 5y ago> i don’t know if TypeScript asserts that x[i] is T | undefined if x is T[] and the length is non-trivial There's a flag for that: https://www.typescriptlang.org/tsconfig#noUncheckedIndexedAccess https://www.typescriptlang.org/tsconfig#noUncheckedIndexedAc...