Skip to content

Type Guards do not reflect on related types #25040

Closed
@lingz

Description

@lingz

TypeScript Version: 2.8

Code

type Identity<T> = T;

function test(
  x: 'a' | 'b',
  y: Identity<typeof x>,
) {
  if (x === 'a') {
    const z = y;
  }
}

Expected behavior:
x has type a
z has type a

Actual behavior:
x has type a
z has type a | b

Metadata

Metadata

Assignees

No one assigned

    Labels

    QuestionAn issue which isn't directly actionable in code

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions