mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-06-10 18:04:18 -05:00
Add infer T constraint inference rule matching up mapped type templates across check/extends types (#43649)
This commit is contained in:
@@ -12613,6 +12613,19 @@ namespace ts {
|
||||
else if (grandParent.kind === SyntaxKind.TypeParameter && grandParent.parent.kind === SyntaxKind.MappedType) {
|
||||
inferences = append(inferences, keyofConstraintType);
|
||||
}
|
||||
// When an 'infer T' declaration is the template of a mapped type, and that mapped type if the extends
|
||||
// clause of a conditional whose check type is also a mapped type, give it the constraint of the template
|
||||
// of the check type's mapped type
|
||||
else if (grandParent.kind === SyntaxKind.MappedType && (grandParent as MappedTypeNode).type &&
|
||||
skipParentheses((grandParent as MappedTypeNode).type!) === declaration.parent && grandParent.parent.kind === SyntaxKind.ConditionalType &&
|
||||
(grandParent.parent as ConditionalTypeNode).extendsType === grandParent && (grandParent.parent as ConditionalTypeNode).checkType.kind === SyntaxKind.MappedType &&
|
||||
((grandParent.parent as ConditionalTypeNode).checkType as MappedTypeNode).type) {
|
||||
const checkMappedType = (grandParent.parent as ConditionalTypeNode).checkType as MappedTypeNode;
|
||||
const nodeType = getTypeFromTypeNode(checkMappedType.type!);
|
||||
inferences = append(inferences, instantiateType(nodeType,
|
||||
makeUnaryTypeMapper(getDeclaredTypeOfTypeParameter(getSymbolOfNode(checkMappedType.typeParameter)), checkMappedType.typeParameter.constraint ? getTypeFromTypeNode(checkMappedType.typeParameter.constraint) : keyofConstraintType)
|
||||
));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user