Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Fix indexed access in conditional type#22707

Merged
ahejlsberg merged 7 commits into
mastermicrosoft/TypeScript:masterfrom
fixIndexedAccessInConditionalTypemicrosoft/TypeScript:fixIndexedAccessInConditionalTypeCopy head branch name to clipboard
Mar 21, 2018
Merged

Fix indexed access in conditional type#22707
ahejlsberg merged 7 commits into
mastermicrosoft/TypeScript:masterfrom
fixIndexedAccessInConditionalTypemicrosoft/TypeScript:fixIndexedAccessInConditionalTypeCopy head branch name to clipboard

Conversation

@ahejlsberg

Copy link
Copy Markdown
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.

Comment thread src/compiler/checker.ts
}

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
Copy Markdown
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
Copy Markdown
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

Morty Proxy This is a proxified and sanitized view of the page, visit original site.