Skip to content

Generic property type widened by conditional #28804

Closed

Description

TypeScript Version: 3.2.1

Search Terms: generic, conditional type, widened

Code

type A = { foo: "a" }
type B = { foo: "b" }
type C = A | B

type Resolve<T extends "a" | "b"> = "a" | "b" extends T ? never : T

type GenericResolve<T extends C> = Resolve<T["foo"]>

type X = Resolve<"a"> // "a"
type Y = Resolve<A["foo"]> // "a"
type Z = GenericResolve<A> // never

type ResolveWithoutCondition<T extends "a" | "b"> = T
type GenericResolveWithoutCondition<T extends C> = ResolveWithoutCondition<T["foo"]>

type ZZ = GenericResolveWithoutCondition<A> // "a"

Expected behavior:
Z should be "a"

Actual behavior:
Z is never

Playground Link: http://www.typescriptlang.org/play/#src=type%20A%20%3D%20%7B%20foo%3A%20%22a%22%20%7D%0D%0Atype%20B%20%3D%20%7B%20foo%3A%20%22b%22%20%7D%0D%0Atype%20C%20%3D%20A%20%7C%20B%0D%0A%0D%0Atype%20Resolve%3CT%20extends%20%22a%22%20%7C%20%22b%22%3E%20%3D%20%22a%22%20%7C%20%22b%22%20extends%20T%20%3F%20never%20%3A%20T%0D%0A%0D%0Atype%20GenericResolve%3CT%20extends%20C%3E%20%3D%20Resolve%3CT%5B%22foo%22%5D%3E%0D%0A%0D%0Atype%20X%20%3D%20Resolve%3C%22a%22%3E%20%2F%2F%20%22a%22%0D%0Atype%20Y%20%3D%20Resolve%3CA%5B%22foo%22%5D%3E%20%2F%2F%20%22a%22%0D%0Atype%20Z%20%3D%20GenericResolve%3CA%3E%20%2F%2F%20never%0D%0A%0D%0Atype%20ResolveWithoutCondition%3CT%20extends%20%22a%22%20%7C%20%22b%22%3E%20%3D%20T%0D%0Atype%20GenericResolveWithoutCondition%3CT%20extends%20C%3E%20%3D%20ResolveWithoutCondition%3CT%5B%22foo%22%5D%3E%0D%0A%0D%0Atype%20ZZ%20%3D%20GenericResolveWithoutCondition%3CA%3E%20%2F%2F%20%22a%22

Related Issues:

Could not find any

Activity

  1. jack-williams commented on Dec 2, 2018

    @jack-williams
    Collaborator

    I think this has been fixed by #28718. Try the latest version of master and see if that works.

  2. ahejlsberg commented on Dec 2, 2018

    @ahejlsberg
    Member

    This is indeed the same issue as #28654 and has been fixed by #28718.

  3. typescript-bot commented on Dec 12, 2018

    @typescript-bot
    Contributor

    This issue has been marked as a duplicate and has seen no activity in the last day. It has been closed automatic house-keeping purposes.

  4. locked as resolved and limited conversation to collaborators on Oct 21, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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