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
That tool is generating illogical code and should be fixed.
Please see this question on StackOverflow. TypeScript does not have, intentionally, the concept between errors and warnings. You can always choose to ignore the errors as it does not effect the emit.
I don't know that it helps much to dismiss the generated code as illogical; 1 == 0 has an obvious meaning (false), and makes sense even to TypeScript pre-2.1. TypeScript 2.1 and up interprets 1 and 0 more narrowly than the tool author probably intended. Inferring literal types (#10676) in this case is a feature that presumably catches enough legitimate errors to justify the occasional pain point like this.
@zq8024: As mentioned, you can ignore the error if you want.
If you have any control over the output of the tool and if the tool is supposed to be outputting TypeScript, then something like
…(function(){return<number>1==0;}
would more clearly communicate to the type checker the intent of the comparison.
If you don't have any control over the output of the tool, or if the tool is only supposed to output plain JavaScript as opposed to TypeScript; and you don't want to ignore errors, maybe having TypeScript check and compile it isn't a great idea? Without knowing more about your build configuration, I don't know if it makes sense, but could you reconfigure it to get the tool and the TypeScript compiler out of each other's way?
Automatically closing this issue for housekeeping purposes. The issue labels indicate that it is unactionable at the moment or has already been addressed.
Activity
kitsonk commentedon Jun 30, 2017
Essentially a dupe of #12794 and works as intended.
TypeScript is intentionally smart enough to know that this is illogical code and you are making an invalid comparison.
zq8024 commentedon Jun 30, 2017
I think it is a warnning, not a error, because it can execute.
that function is auto generated by tool.
kitsonk commentedon Jun 30, 2017
That tool is generating illogical code and should be fixed.
Please see this question on StackOverflow. TypeScript does not have, intentionally, the concept between errors and warnings. You can always choose to ignore the errors as it does not effect the emit.
jcalz commentedon Jun 30, 2017
I don't know that it helps much to dismiss the generated code as illogical;
1 == 0
has an obvious meaning (false
), and makes sense even to TypeScript pre-2.1. TypeScript 2.1 and up interprets1
and0
more narrowly than the tool author probably intended. Inferring literal types (#10676) in this case is a feature that presumably catches enough legitimate errors to justify the occasional pain point like this.@zq8024: As mentioned, you can ignore the error if you want.
If you have any control over the output of the tool and if the tool is supposed to be outputting TypeScript, then something like
would more clearly communicate to the type checker the intent of the comparison.
If you don't have any control over the output of the tool, or if the tool is only supposed to output plain JavaScript as opposed to TypeScript; and you don't want to ignore errors, maybe having TypeScript check and compile it isn't a great idea? Without knowing more about your build configuration, I don't know if it makes sense, but could you reconfigure it to get the tool and the TypeScript compiler out of each other's way?
mhegazy commentedon Aug 17, 2017
Automatically closing this issue for housekeeping purposes. The issue labels indicate that it is unactionable at the moment or has already been addressed.