Skip to content

Comparing numeric enum to number narrows variable to 'never'Β #42442

Closed
@ajafff

Description

@ajafff

Bug Report

πŸ”Ž Search Terms

enum, number, never

πŸ•— Version & Regression Information

  • This changed between versions 3.8.3 and 3.9.7

⏯ Playground Link

Playground link with relevant code

πŸ’» Code

enum E {
    a = 1,
    b = 2,
}

declare let v: E;
if (v !== 0) {
    v &= E.a;
}

πŸ™ Actual behavior

v is narrowed to never inside the IfStatement. The compound assignment gives a compile error: Type 'number' is not assignable to type 'never'.(2322)

πŸ™‚ Expected behavior

v is still of type E and there's no error.

Metadata

Metadata

Assignees

Labels

BugA bug in TypeScriptFix AvailableA PR has been opened for this issueRescheduledThis issue was previously scheduled to an earlier milestone

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions