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

Fix indexed access in conditional type #22707

Merged
merged 7 commits into from
Mar 21, 2018

Conversation

ahejlsberg
Copy link
Member

With this PR, when the checked type in a conditional type is an indexed access type, we now add an implicit constraint to the type in the true branch.

Also, this PR fixes an issue where implicit constraints are not combined in nested conditional types.

Fixes #21729.

}

function getImpliedConstraint(typeVariable: TypeVariable, checkNode: TypeNode, extendsNode: TypeNode): Type {
return isUnaryTupleTypeNode(checkNode) && isUnaryTupleTypeNode(extendsNode) ? getImpliedConstraint(typeVariable, (<TupleTypeNode>checkNode).elementTypes[0], (<TupleTypeNode>extendsNode).elementTypes[0]) :
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: shorten this line

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, if you made isUnaryTupleTypeNode a type predicate, you could potentially avoid the type assertions

@ahejlsberg ahejlsberg merged commit e5f6ed0 into master Mar 21, 2018
@ahejlsberg ahejlsberg deleted the fixIndexedAccessInConditionalType branch March 21, 2018 22:18
@microsoft microsoft locked and limited conversation to collaborators Jul 25, 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.

Bug: Mapped type does not satisfy the constraint it just matched in conditional type
3 participants