Skip to content

Switch statement does not flag non-comparable cases with non-overlapping literal and non-literal union types #38686

Closed
@ericbf

Description

@ericbf

TypeScript Version: 3.0.0-dev.201xxxxx

Search Terms:
Switch, non-comparable types, false negative

Code

declare let message: number | "hello"

switch (message) {
    case "hi":
        break
}

Expected behavior:
Type '"hi"' is not comparable to type 'number | "hello"'.
(2678)

Actual behavior:
No error.

Playground Link: https://www.typescriptlang.org/play/?ssl=1&ssc=31&pln=1&pc=22#code/CYUwxgNghgTiAEEQBd4FsQGdNQOYgC54A7AVzQCMQZ4AfeAIgAsQIIB7BgKC8wHcAlsjBN4ACgzY8IAJTwA3l3jL4YKJgTMBDAkpX6KcKAGsuAXyA

Related Issues: None that I found

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugA bug in TypeScript

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions