You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
TypeScript Version: 3.1.0-dev.20180717
Error: This condition will always return 'false' since the types '"work1"' and '"work2"' have no overlap.
Error: Type '"work2"' is not comparable to type '"work1"'. TypeScript Version: 2.9.2
Error: Operator '==' cannot be applied to types '"work1"' and '"work2"'.
Error: Type '"work2"' is not comparable to type '"work1"'.
Search Terms:
Operator '==' cannot be applied to types
This condition will always return 'false' since the types have no overlap.
Type is not comparable to type. Code
function doWorkIf(work: 'work1' | 'work2'): void {
work = 'work1'; // made this for debug purpose and TS alerts error
if (work == 'work1') {
// do something
}
if (work == 'work2') { // YEA typescript, I know what I do, why you alert me??
// do something
}
}
function doWorkCase(work: 'work1' | 'work2'): void {
work = 'work1'; // made this for debug purpose and TS alerts error
switch (work) {
case 'work1':
// do something
break;
case 'work2':
// do something
break;
}
}
Expected behavior:
no error Actual behavior:
error Playground Link:link
Sorry, but it's me again. Why I have to write ugly code removing typing info (work = 'work1' as any; fixes the issue) to make my correct code work? I already specified allowUnreachableCode option to true. Why TS alerts me? This kind of alerts should be an linting rules, or may be configurable feature. I read #25642 (comment). I think all we shoult think about alerting correct code. It's really bad idea. Yea, I have to throw this error detection away in my own fork, but I am not always use the fork, its made for special puprose. I love typescript, and using it from 1.3 but this feature is really makes me angry.
Now constructive proposals:
Create additional compiler option, like allowUnreachableCode to disable it.
Move this error to ESLint or TSLint.
Disable this error detection while allowUnreachableCode is set to true.
Totally throw away this featue.
Improve it with nominal types detection, and make this error detection safe for correct code.
Any kind of solution will be much better than now. May be there is another ways to solve it... Sorry, I'm really angry. Typescript is the best thing that happens in web, and I want to make it better.
The text was updated successfully, but these errors were encountered:
Yea, there is many ways to fool compiler. And I have no claims to flow analysys. This is only issue about comparing things that TypeScript thinks uncomparable.
There are limitations of control flow analysis that we are aware of. more about these in #9998. The current design and implementation tries to balance value added vs. false positives. I do not think there is a solution that catches all bugs, and not flag valid use cases. User intent is hard to figure out in many of these cases.
Automatically closing this issue for housekeeping purposes. The issue labels indicate that it is unactionable at the moment or has already been addressed.
TypeScript Version: 3.1.0-dev.20180717
Error: This condition will always return 'false' since the types '"work1"' and '"work2"' have no overlap.
Error: Type '"work2"' is not comparable to type '"work1"'.
TypeScript Version: 2.9.2
Error: Operator '==' cannot be applied to types '"work1"' and '"work2"'.
Error: Type '"work2"' is not comparable to type '"work1"'.
Search Terms:
Operator '==' cannot be applied to types
This condition will always return 'false' since the types have no overlap.
Type is not comparable to type.
Code
Expected behavior:
no error
Actual behavior:
error
Playground Link: link
Related Issues: #25642
Sorry, but it's me again. Why I have to write ugly code removing typing info (
work = 'work1' as any;
fixes the issue) to make my correct code work? I already specified allowUnreachableCode option to true. Why TS alerts me? This kind of alerts should be an linting rules, or may be configurable feature. I read #25642 (comment). I think all we shoult think about alerting correct code. It's really bad idea. Yea, I have to throw this error detection away in my own fork, but I am not always use the fork, its made for special puprose. I love typescript, and using it from 1.3 but this feature is really makes me angry.Now constructive proposals:
Any kind of solution will be much better than now. May be there is another ways to solve it... Sorry, I'm really angry. Typescript is the best thing that happens in web, and I want to make it better.
The text was updated successfully, but these errors were encountered: