Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

null comparison fails in switch statement with --strictNullChecks #8971

Copy link
Copy link
@bmayen

Description

@bmayen
Issue body actions

TypeScript Version:

nightly (1.9.0-dev.20160604-1.0)

Code

let foo:number|null = 0;

switch(foo) {
  case null:
    break;
  case 0:
    console.log('bar');
}

Expected behavior:
Null check should be allowed

Actual behavior:
Compiler complains "TypeScript Type 'null' is not comparable to type 'number'. (TS2678)"

Note:
If I add an 'if' condition before the switch, the compiler does not complain about either the 'if' or the switch. For instance:

let foo:number|null = 0;

if (foo === null) { console.log('bar'); }

switch(foo) {
  case null:
    break;
  case 0:
    console.log('bar');
}
Reactions are currently unavailable

Metadata

Metadata

Assignees

Labels

BugA bug in TypeScriptA bug in TypeScriptFixedA PR has been merged for this issueA PR has been merged for this issue

Type

No type
No fields configured for issues without a type.

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions

    Morty Proxy This is a proxified and sanitized view of the page, visit original site.