Skip to content

TS2365  #16854

Closed
Closed
TS2365 #16854
@zq8024

Description

@zq8024

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

compile,then typescript show TS2365 error

Activity

kitsonk

kitsonk commented on Jun 30, 2017

@kitsonk
Contributor

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

zq8024 commented on Jun 30, 2017

@zq8024
Author

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

kitsonk

kitsonk commented on Jun 30, 2017

@kitsonk
Contributor

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

jcalz commented on Jun 30, 2017

@jcalz
Contributor

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?

mhegazy

mhegazy commented on Aug 17, 2017

@mhegazy
Contributor

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Working as IntendedThe behavior described is the intended behavior; this is not a bug

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @zq8024@jcalz@kitsonk@RyanCavanaugh@mhegazy

        Issue actions

          TS2365 · Issue #16854 · microsoft/TypeScript