Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generic property type widened by conditional #28804

Closed
alexfoxgill opened this issue Dec 2, 2018 · 3 comments
Closed

Generic property type widened by conditional #28804

alexfoxgill opened this issue Dec 2, 2018 · 3 comments
Labels
Duplicate An existing issue was already created

Comments

@alexfoxgill
Copy link

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

@jack-williams
Copy link
Collaborator

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

@ahejlsberg
Copy link
Member

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

@ahejlsberg ahejlsberg added the Duplicate An existing issue was already created label Dec 2, 2018
@typescript-bot
Copy link
Collaborator

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Duplicate An existing issue was already created
Projects
None yet
Development

No branches or pull requests

4 participants