Skip to content

linter: no-unused-expressions does not support satisfies expressions #14248

@matthieu-foucault

Description

@matthieu-foucault

What version of Oxlint are you using?

1.16.0

What command did you run?

oxlint

What does your .oxlintrc.json config file look like?

{
    "rules": {
        "typescript/no-unused-expressions": "error"
    }
}

What happened?

The satisfies statement below is reported as an unused expression. It is a valid type assertion which is handy to ensure switch statements are exhaustive (e.g. here Typescript reports Type '"baz"' does not satisfy the expected type 'never')

type FooBarBaz = 'foo' | 'bar' | 'baz';

export function satisfiesTest(c: FooBarBaz): string {
    switch(c) {
        case 'foo':
            return 'foo';
        case 'bar':
            return 'bar';
        default:
            c satisfies never;
            return '';
    }
}
  × eslint(no-unused-expressions): Disallow unused expressions
    ╭─[src/satisfies.ts:10:13]
  9 │         default:
 10 │             c satisfies never;
    ·             ──────────────────
 11 │             return '';
    ╰────
  help: Consider removing this expression

Note that even though the configuration uses typescript/no-unused-expressions, the error is reported under the no-unused-expressions rule. Even though they're documented under different names, both seem to be pointing to the same rule? Not sure if that's expected, but that is confusing

Metadata

Metadata

Assignees

Labels

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions