strict-type-predicates reports 'Expression is always true.' which is not true #2783
Comments
Remove the type annotation `:number` which is wrong anyway. That should
make it work
Am 18.05.2017 17:19 schrieb "Martin-Wegner" <notifications@github.com>:
… Bug Report
- *TSLint version*: 5.2.0
- *TypeScript version*: 2.3.2
- *Running TSLint via*: ng lint --type-check from Angular CLI
TypeScript code being linted
['a', 'b', 'c'].map((s: string) => {
if (s === 'b') {
return undefined;
}
return 1;
}).filter((n: number) => n !== undefined);
with tslint.json configuration:
{
"rules": {
"strict-type-predicates": true
}
}
Actual behavior
ERROR: ...: Expression is always true.
Expected behavior
No error.
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
<#2783>, or mute the thread
<https://github.com/notifications/unsubscribe-auth/ALaeKC67o3zB_pdCKG_RBNA0WTkRB4Tqks5r7GGSgaJpZM4NfZiq>
.
|
Why is Without type annotation the same error occurs. |
Your function maps to The bug with |
I omitted it and the same error occurs... |
Using |
That indeed looks like a bug. Do you have strictNullChecks enabled in your tsconfig.json? |
No Btw: |
This rule does not work as expected without strictNullChecks, because the current implementation assumes that it's enabled. I doubt it would be useful to add special handling for declare var num: number;
typeof num === "function"; // this will never be true
typeof num === "symbol"; // this will never be true
typeof num === "string"; // this will never be true
...
typeof num === "object"; // could be true when num === null
typeof num === "undefined"; // could be true when num === undefined |
Of course we could do a better job documenting that behavior. Maybe even warn at runtime if this rule is used without strictNullChecks (and not apply this rule?). |
Bug Report
TypeScript code being linted
with
tslint.json
configuration:Actual behavior
Expected behavior
No error.
The text was updated successfully, but these errors were encountered: