Skip to content

Bug with type discrimination and string literal types. #13628

Closed

Description

The following code gives an error on the assignment to x:

type Bar = "A" | "B"
type Foo = { key: "a", name: string } | { key: "b", name: Bar }

const x: Foo = { key: "b", name: "A" }

There are multiple weird things that get rid of the error, including:

  1. Changing { key: "a", name: string } to { key: "a" }.
  2. Changing name: "A" to name: "A" as Bar
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Labels

    DuplicateAn existing issue was already created

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions