Repository navigation
TS2365 #16854
Description
Activity
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.
I think it is a warnning, not a error, because it can execute.
that function is auto generated by tool.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.
Reacted by Aluan HaddadI don't know that it helps much to dismiss the generated code as illogical;
1 == 0has an obvious meaning (false), and makes sense even to TypeScript pre-2.1. TypeScript 2.1 and up interprets1and0more 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?
- addedWorking as IntendedThe behavior described is the intended behavior; this is not a bugThe behavior described is the intended behavior; this is not a bug
on Jun 30, 2017 Automatically closing this issue for housekeeping purposes. The issue labels indicate that it is unactionable at the moment or has already been addressed.
- locked and limited conversation to collaborators
on Jun 14, 2018
code:
function(){ return 1 == 0; }compile,then typescript show TS2365 error