Closed
Description
Bug Report
🔎 Search Terms
- null check
- record
- noUncheckedIndexedAccess
🕗 Version & Regression Information
- This is the behavior in every version I tried, and I reviewed the FAQ for entries about noUncheckedIndexedAccess option and null check
⏯ Playground Link
Playground link with relevant code
💻 Code
const arr: string[] = []
function addDefinitions(defs: Record<string, string>): void {
Object.keys(defs).forEach((type: string): void => {;
if (defs[type] != undefined) {
arr.push(defs[type]); // ❌ ts error
}
});
}
🙁 Actual behavior
In my code i get a Argument of type 'Definition | undefined' is not assignable to parameter of type 'Definition'.
error. But as you see i check the object value with if (defs[type] != undefined)
. But at this.addDefinition(type, defs[type]);
the error is thrown anyway.
The active option noUncheckedIndexedAccess
will produces this error. But as you see there is a null check so that this error should not be thrown.
🙂 Expected behavior
Because of the null check this error should not be shown.