no-unused-expressions lint error is thrown when optional chaining a function evaluation, i.e. fn?.(). This should not occur since it is not an expression.
const fn = (optionalFnParameter?: () => void): void => {
optionalFnParameter?.(); // LINT ERROR
};
Expected Result
No exception, because the function is not returning anything
Actual Result
"no-unused-expressions" lint error
| package | version |
| ---------------------------------- | ------- |
| @typescript-eslint/eslint-plugin | 2.16.0 |
| @typescript-eslint/parser | 2.16.0 |
| TypeScript | 3.7.5 |
| ESLint | 5.16.0 |
| node | 12.8.1 |
| npm | `6.10.2 |
Make sure you are using our extension rule.
https://github.com/typescript-eslint/typescript-eslint/blob/master/docs/getting-started/linting/FAQ.md#i-am-using-a-rule-from-eslint-core-and-it-doesnt-work-correctly-with-typescript-code
Patch the config here:
rules: {
+ 'no-unused-expressions': 'off',
+ '@typescript-eslint/no-unused-expressions': 2,
},
Just as a note, if you were using the recommended config the patch @zombieJ suggested is not present. It is present already if you are using the all config.
Most helpful comment
Patch the config here: