Skip to content

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

Closed
@iliubinskii

Description

@iliubinskii

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