Fix non-homomorphic mapped type constraint issues (#41807)

* Less aggressive wildcard check, 'keyof any' constraint for 'infer T' in mapped type constraint position

* Accept new baselines

* Add regression tests
This commit is contained in:
Anders Hejlsberg
2020-12-03 18:36:45 -08:00
committed by GitHub
parent 143d1104ab
commit cd37a327a7
6 changed files with 128 additions and 7 deletions

View File

@@ -12081,6 +12081,11 @@ namespace ts {
else if (grandParent.kind === SyntaxKind.TemplateLiteralTypeSpan) {
inferences = append(inferences, stringType);
}
// When an 'infer T' declaration is in the constraint position of a mapped type, we infer a 'keyof any'
// constraint.
else if (grandParent.kind === SyntaxKind.TypeParameter && grandParent.parent.kind === SyntaxKind.MappedType) {
inferences = append(inferences, keyofConstraintType);
}
}
}
}
@@ -15281,8 +15286,7 @@ namespace ts {
}
}
// If the constraint type of the instantiation is the wildcard type, return the wildcard type.
const result = <MappedType>instantiateAnonymousType(type, mapper);
return getConstraintTypeFromMappedType(result) === wildcardType ? wildcardType : result;
return instantiateType(getConstraintTypeFromMappedType(type), mapper) === wildcardType ? wildcardType : instantiateAnonymousType(type, mapper);
}
function getModifiedReadonlyState(state: boolean, modifiers: MappedTypeModifiers) {