Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork2.8k
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 havesearched for related issues and found none that matched my issue.
- I haveread the FAQ and my problem is not listed.
Playground Link
Repro Code
constsomeArray=[{id:"idOne",type:"typeA"},{id:"idOne",type:"typeC"},{id:"idTwo",type:"typeA"},{id:"idTwo",type:"typeB"},{id:"idThree",type:"typeA"}];typeSomeType=Record<string,string[]>;someArray.reduce<SomeType>((entries,iteratee)=>{const{ id, type}=iteratee;constentry=entries[id]??=[];entry.push(type);returnentries;},{});
ESLint Config
module.exports={parser:"@typescript-eslint/parser",rules:{"@typescript-eslint/no-unneccessary-condition":"error"},};
tsconfig
{"compilerOptions": {"strictNullChecks":true,"noUncheckedIndexedAccess":true }}
Expected Result
Since entries has a type ofRecord<string, string[]>
item fetched via index will give either an item or undefined.
TypeScript seems to recognize this
Actual Result
@typescript-eslint is under the impression that it will always get a result from accessing the object via index and flags the use of??=
as an unnecessary condition.
Additional Info
No response