Accurate constraintType for indexedAccessType (#53059)

This commit is contained in:
SHIMA RYUHEI
2023-03-22 04:54:05 +09:00
committed by GitHub
parent 3d2c3442db
commit 84a09c762b
6 changed files with 387 additions and 0 deletions

View File

@@ -21583,6 +21583,17 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
else if (result = isRelatedTo(getTypeWithThisArgument(constraint, source), target, RecursionFlags.Source, reportErrors && constraint !== unknownType && !(targetFlags & sourceFlags & TypeFlags.TypeParameter), /*headMessage*/ undefined, intersectionState)) {
return result;
}
if (sourceFlags & TypeFlags.IndexedAccess) {
const indexType = (source as IndexedAccessType).indexType;
if (indexType.flags & TypeFlags.Index) {
const unresolvedIndexConstraint = getBaseConstraintOfType((indexType as IndexType).type);
const indexConstraint = unresolvedIndexConstraint && unresolvedIndexConstraint !== noConstraintType ? getIndexType(unresolvedIndexConstraint) : keyofConstraintType;
const constraint = getIndexedAccessType((source as IndexedAccessType).objectType, indexConstraint);
if (result = isRelatedTo(constraint, target, RecursionFlags.Source, /*reportErrors*/ false, /*headMessage*/ undefined, intersectionState)) {
return result;
}
}
}
if (isMappedTypeGenericIndexedAccess(source)) {
// For an indexed access type { [P in K]: E}[X], above we have already explored an instantiation of E with X
// substituted for P. We also want to explore type { [P in K]: E }[C], where C is the constraint of X.