-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Closed as not planned
Closed as not planned
Copy link
Labels
bugSomething isn't workingSomething isn't workingduplicateThis issue or pull request already existsThis issue or pull request already existspackage: eslint-pluginIssues related to @typescript-eslint/eslint-pluginIssues related to @typescript-eslint/eslint-plugin
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 someArray = [
{ id: "idOne", type: "typeA" },
{ id: "idOne", type: "typeC" },
{ id: "idTwo", type: "typeA" },
{ id: "idTwo", type: "typeB" },
{ id: "idThree", type: "typeA" }
];
type SomeType = Record<string, string[]>;
someArray.reduce<SomeType>((entries, iteratee) => {
const { id, type } = iteratee;
const entry = entries[id] ??= [];
entry.push(type);
return entries;
}, {});
ESLint Config
module.exports = {
parser: "@typescript-eslint/parser",
rules: {
"@typescript-eslint/no-unneccessary-condition": "error"
},
};
tsconfig
Expected Result
Since entries has a type of Record<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
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't workingduplicateThis issue or pull request already existsThis issue or pull request already existspackage: eslint-pluginIssues related to @typescript-eslint/eslint-pluginIssues related to @typescript-eslint/eslint-plugin