Reinstate constraint check for template literal types (#43661)

* Add missing constraint check for template literal types

* Add regression test
This commit is contained in:
Anders Hejlsberg
2021-04-13 12:17:55 -10:00
committed by GitHub
parent 5a6a499d0e
commit 5977233fd1
6 changed files with 95 additions and 0 deletions

View File

@@ -18420,6 +18420,16 @@ namespace ts {
return result;
}
}
else if (source.flags & TypeFlags.TemplateLiteral) {
if (!(target.flags & TypeFlags.TemplateLiteral)) {
const baseConstraint = getBaseConstraintOfType(source);
const constraint = baseConstraint && baseConstraint !== source ? baseConstraint : stringType;
if (result = isRelatedTo(constraint, target, reportErrors)) {
resetErrorInfo(saveErrorInfo);
return result;
}
}
}
else if (source.flags & TypeFlags.StringMapping) {
if (target.flags & TypeFlags.StringMapping && (<StringMappingType>source).symbol === (<StringMappingType>target).symbol) {
if (result = isRelatedTo((<StringMappingType>source).type, (<StringMappingType>target).type, reportErrors)) {