Closed
Description
Bug Report
type guard in undefined array indexed access
🔎 Search Terms
🕗 Version & Regression Information
- This changed from version 4 with the introduction of noUncheckedIndexedAccess
- This is the behavior in every version I tried, and I reviewed the FAQ for entries about _________
- I was unable to test this on prior versions because _______
⏯ Playground Link
💻 Code
const abc: Record<string,string> = {};
function bar( arg: string ) {
if ( arg in abc ) {
const data = abc[ arg ];
}
}
🙁 Actual behavior
data is string|undefined
despite it being typeguarded with "in" on a Record<string, string>
which means that it cannot be undefined
🙂 Expected behavior
data
should be string
The current bug causes either lots of redundant code (as we have to typeguard for undefined again separately) or disabling noUncheckedIndexAccess
which would snooze tons of potential bugs though.