What version of Oxlint are you using?
1.71.0
What command did you run?
npx oxlint
What does your .oxlintrc.json (or oxlint.config.ts) config file look like?
export default defineConfig({
plugins: ['unicorn'],
rules: {
'unicorn/prefer-native-coercion-functions': 'warn',
},
});
What happened?
test.ts
const yes = 'str';
const maybe = undefined as string | undefined;
const things = [yes, maybe].filter((thing): thing is string => Boolean(thing));
function doStuff(stuff: string[]) {
return stuff;
}
doStuff(things);
Output from npx oxlint:
⚠ unicorn(prefer-native-coercion-functions): The function is equivalent to `Boolean`. Call `Boolean` directly.
╭─[test.ts:3:36]
2 │ const maybe = undefined as string | undefined;
3 │ const things = [yes, maybe].filter((thing): thing is string => Boolean(thing));
· ──────────────────────────────────────────
4 │ function doStuff(stuff: string[]) {
╰────
Upstream has the same issue. Had, was fixed in v64.0.0. Doing the suggested fix to const things = [yes, maybe].filter(Boolean); leads to a type error since Boolean doesn't narrow:
test.ts:7:9 - error TS2345: Argument of type '(string | undefined)[]' is not assignable to parameter of type 'string[]'.
Type 'string | undefined' is not assignable to type 'string'.
Type 'undefined' is not assignable to type 'string'.
doStuff(things);
~~~~~~
A call without a return type (const things = [yes, maybe].filter((thing) => Boolean(thing))) is a valid lint error since things is still (string | undefined)[].
What version of Oxlint are you using?
1.71.0
What command did you run?
npx oxlint
What does your
.oxlintrc.json(oroxlint.config.ts) config file look like?What happened?
test.ts
Output from
npx oxlint:Upstream has the same issue.Had, was fixed in v64.0.0. Doing the suggested fix toconst things = [yes, maybe].filter(Boolean);leads to a type error sinceBooleandoesn't narrow:A call without a return type (
const things = [yes, maybe].filter((thing) => Boolean(thing))) is a valid lint error sincethingsis still(string | undefined)[].