Skip to content

TypeScript: infer extends within union fails to compile if it's at the top level #3574

@satohshi

Description

@satohshi

Issue

The following code fails to compile with error Expected "?" but found end of file:

type InferUnion<T> = T extends { a: infer U extends number } | infer U extends number
    ? U
    : never

The issue seems to be with infer U extends at the top level of a union, as the following compiles fine:

type InferUnion<T> = T extends { a: infer U extends number } | { b: infer U extends number }
    ? U
    : never

Reproduction

esbuild playground

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions