-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Closed
Labels
enhancementNew feature or requestNew feature or requestpackage: eslint-pluginIssues related to @typescript-eslint/eslint-pluginIssues related to @typescript-eslint/eslint-plugin
Description
- I have tried restarting my IDE and the issue persists.
- I have updated to the latest version of the packages.
- I have read the FAQ and my problem is not listed.
Repro
{
"rules": {
"@typescript-eslint/strict-boolean-expressions": "warn"
}
}function test<S>(): void {
const foo = getEmptyArray<S>();
if (foo.pop()) {
throw new Error();
}
const bar = getEmptyArray<boolean>();
if (bar.pop()) {
throw new Error();
}
}
function getEmptyArray<S>(): S[] {
return [];
}Expected Result
Both if (foo.pop()) and if (bar.pop()) should produce warnings. Both are potentially undefined and most likely not booleans. foo.pop() has the return type S | undefined and bar has number | undefined.
Actual Result
if (foo.pop()) does not produce a warning despite almost certainly not being a boolean.
I found that if the condition is a union with a type parameter (S | anything), then strict-boolean-expressions won't report anything. This is a problem because that means that the rule cannot check all conditions inside generic functions.
Additional Info
Versions
| package | version |
|---|---|
@typescript-eslint/eslint-plugin |
4.28.4 |
@typescript-eslint/parser |
4.23.0 |
TypeScript |
4.2.4 |
ESLint |
7.26.0 |
node |
14.15.4 |
Metadata
Metadata
Assignees
Labels
enhancementNew feature or requestNew feature or requestpackage: eslint-pluginIssues related to @typescript-eslint/eslint-pluginIssues related to @typescript-eslint/eslint-plugin