-
-
Notifications
You must be signed in to change notification settings - Fork 877
Closed
Labels
A-linterArea - LinterArea - Linter
Description
What version of Oxlint are you using?
1.51.0, oxlint-tsgolint 0.16.0
What command did you run?
oxlint
What does your .oxlintrc.json (or oxlint.config.ts) config file look like?
What happened?
@typescript-eslint/no-unnecessary-condition reports a false positive when indexing into a Partial<Record<R, T[]>> and using ?? [] as a fallback. With noUncheckedIndexedAccess: true in tsconfig.json, the index access type is T[] | undefined, so the nullish coalescing is necessary. oxlint incorrectly considers the value non-nullish.
tsconfig.json:
{
"compilerOptions": {
"module": "ESNext",
"target": "ES2023",
"moduleResolution": "bundler",
"strict": true,
"noEmit": true,
"noUncheckedIndexedAccess": true,
"skipLibCheck": true
},
"include": ["src"]
}src/example.ts:
export function groupBy<T, R extends string | number>(list: T[], func: (item: T) => R) {
return list.reduce(
(obj, item) => {
const existingItems = obj[func(item)] ?? [];
return { ...obj, [func(item)]: [...existingItems, item] };
},
{} as Partial<Record<R, T[]>>
);
}
Reported diagnostic:
x typescript-eslint(no-unnecessary-condition): Unnecessary optional chain on a non-nullish value.
,-[src/example.ts:4:26]
3 | (obj, item) => {
4 | const existingItems = obj[func(item)] ?? [];
: ^^^^^^^^^^^^^^^
5 | return { ...obj, [func(item)]: [...existingItems, item] };
`----
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
A-linterArea - LinterArea - Linter
{ "plugins": ["typescript"], "options": { "typeAware": true }, "rules": { "@typescript-eslint/no-unnecessary-condition": "error" } }