In this code
const arr = ['hello', 'world'];
const x = arr[2];
const y = arr[0.5];
arr
is a string[]
, and 10
and 0.5
are number
s, so TS implies that 10
and 0.5
can index arr
, therefore inferring that x
and y
are string
s too, while at runtime they'll be undefined
.
Is there a configuration option I can write in my tsconfig.json
that basically tells typescript "if you're not sure that arr: T[]
has an element at i
, do not infer that arr[i]
is a T
"?