Skip to content

Confusing error message: Operator '===' cannot be applied to types '1' and '0'. #25245

Closed
@mjbvz

Description

@mjbvz

TypeScript Version: 3.0.0-dev.20180623

Search Terms:

Code

function foo(x: [number]) {
    return x.length === 0;
}

Bug:
The error message is: Operator '===' cannot be applied to types '1' and '0'.

I found this error very confusing. It took me a while to understand that the error meant that the type on the left hand side was 1.

In this case, I think we should instead report that the condition always evaluates to false.

Related Issues:

/cc @chrisdias

Metadata

Metadata

Labels

BugA bug in TypeScriptDomain: Error MessagesThe issue relates to error messagingFix AvailableA PR has been opened for this issueFixedA PR has been merged for this issueHelp WantedYou can do this

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions