Skip to content

Inferred type parameter constraints#21709

Merged
ahejlsberg merged 9 commits intomasterfrom
inferredTypeParameterConstraints
Feb 7, 2018
Merged

Inferred type parameter constraints#21709
ahejlsberg merged 9 commits intomasterfrom
inferredTypeParameterConstraints

Conversation

@ahejlsberg
Copy link
Copy Markdown
Member

With this PR we infer constraints for infer X type parameters in conditional types in certain circumstances. Specifically, when an infer X type parameter declaration occurs as a type argument in a type reference, we infer the constraint of the corresponding type parameter as the constraint of X. For example:

type Foo<T extends string> = { foo: T };
type Bar<T extends string> = { bar: T };
type Barify<T> = T extends Foo<infer X> ? Bar<X> : T;

Here, because the infer X declaration occurs as a type argument for the T type parameter in Foo, and because T has a constraint of string, the inferred constraint for X is string. Therefore, X meets the constraint required by Bar<T>.

Fixes #21631.

@ahejlsberg ahejlsberg merged commit 3d99812 into master Feb 7, 2018
@ahejlsberg ahejlsberg deleted the inferredTypeParameterConstraints branch February 7, 2018 21:16
@microsoft microsoft locked and limited conversation to collaborators Jul 3, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants