Skip to content

Incorrect post-narrowing merge of typeof symbol | {} | (() => void) #45467

Description

Bug Report

🔎 Search Terms

switch incorrectly narrows type

🕗 Version & Regression Information

v4.3.5

⏯ Playground Link

Playground link with relevant code

💻 Code

const symbol = Symbol("Test");

function f(x: 1 | "a" | typeof symbol | {} | (() => void)): void {
  switch (typeof x) {
    case "number":
    case "object":
    case "string":
    case "symbol":
  }

  switch (typeof x) {
    case "function":
    case "object":
    case "string":
    case "symbol":
  }

  switch (typeof x) {
    case "function":
    case "number":
    case "string":
    case "symbol":
  }

  switch (typeof x) {
    case "function":
    case "number":
    case "object":
    case "symbol":
  }

  switch (typeof x) {
    case "function":
    case "number":
    case "object":
    case "string":
  }

  switch (typeof x) {
    case "function":
    case "number":
    case "object":
    case "string":
    case "symbol":
  }
}

🙁 Actual behavior

Starting from 4th switch the type of x is narrowed to {}.

Screen

🙂 Expected behavior

The type of x should not be narrowed

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