Closed
Description
Before You File a Bug Report Please Confirm You Have Done The Following...
- I have tried restarting my IDE and the issue persists.
- I have updated to the latest version of the packages.
- I have searched for related issues and found none that matched my issue.
- I have read the FAQ and my problem is not listed.
Playground Link
Repro Code
function example<T extends object>(
arg: T,
key: keyof T
): void {
const b1 = arg[key] != null;
const b2 = arg[key] ?? 'fallback';
}
const o: { foo: string|null } = { foo: null };
example(o, 'foo');
ESLint Config
module.exports = {
"rules": {
"@typescript-eslint/no-unnecessary-condition": "error"
}
};
tsconfig
Expected Result
No error should be reported since it is possible to supply null values on properties of the incoming object in the example.
Actual Result
An error gets reported saying that null and the value of the type that it is compared with does not have any overlap:
Unnecessary conditional, the types have no overlap. 5:14 - 5:30
Unnecessary conditional, expected left-hand side of `??` operator to be possibly null or undefined. 6:14 - 6:22
Additional Info
No response