Closed as not planned
Closed as not planned
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
const testObj: Record<string, number[]> = {}
const key = 10;
testObj[key] ??= [];
// the below code works fine for some reason which is why you also need
// the rule @typescript-eslint/prefer-nullish-coalescing to be active for this bug to show
// if (!testObj[key]) {
// testObj[key] = [];
// }
testObj[key].push(10);
ESLint Config
{
"rules": {
"@typescript-eslint/prefer-nullish-coalescing": "error",
"@typescript-eslint/no-unnecessary-condition": "error"
}
}
tsconfig
Expected Result
Shows an error showing that using a number for the key instead of a string is the issue.
Actual Result
Shows the following error
Unnecessary conditional, expected left-hand side of
?? operator to be possibly null or undefined
despite that not actually being the issue
Additional Info
No response