Skip to content

Type 'T' is not assignable to type 'T extends Sub ? Sub : T'.Β #48746

@taralx

Description

@taralx

Bug Report

πŸ”Ž Search Terms

variance, conditional, subtype, limit

πŸ•— Version & Regression Information

  • This is the behavior in every version I tried, and I reviewed the FAQ for entries about variance and conditionals.

⏯ Playground Link

Playground link with relevant code

πŸ’» Code

interface Base {
    base: unknown;
}

interface Sub extends Base {
    sub: unknown;
}

function transform<T extends Base>(t: T): T extends Sub ? Sub : T {
    return t;
}

πŸ™ Actual behavior

"Type 'T' is not assignable to type 'T extends Sub ? Sub : T'."

πŸ™‚ Expected behavior

No errors. Either T extends Sub, and so is assignable to it, or it doesn't, and so is assignable to itself.

Metadata

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