Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TS2365 #16854

Closed
zq8024 opened this issue Jun 30, 2017 · 5 comments
Closed

TS2365 #16854

zq8024 opened this issue Jun 30, 2017 · 5 comments
Labels
Working as Intended The behavior described is the intended behavior; this is not a bug

Comments

@zq8024
Copy link

zq8024 commented Jun 30, 2017

code:
function(){ return 1 == 0; }

compile,then typescript show TS2365 error

@kitsonk
Copy link
Contributor

kitsonk commented 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
Copy link
Author

zq8024 commented Jun 30, 2017

I think it is a warnning, not a error, because it can execute.
that function is auto generated by tool.

@kitsonk
Copy link
Contributor

kitsonk commented 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
Copy link
Contributor

jcalz commented 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 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?

@RyanCavanaugh RyanCavanaugh added the Working as Intended The behavior described is the intended behavior; this is not a bug label Jun 30, 2017
@mhegazy
Copy link
Contributor

mhegazy commented 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.

@mhegazy mhegazy closed this as completed Aug 17, 2017
@microsoft microsoft locked and limited conversation to collaborators Jun 14, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Working as Intended The behavior described is the intended behavior; this is not a bug
Projects
None yet
Development

No branches or pull requests

5 participants