Merge pull request #23806 from Microsoft/objectAndUnconstrainedTypeParameter

Unconstrained type variable not assignable to 'object'
This commit is contained in:
Anders Hejlsberg
2018-05-01 13:24:16 -07:00
committed by GitHub
6 changed files with 178 additions and 9 deletions

View File

@@ -10716,19 +10716,18 @@ namespace ts {
return result;
}
}
let constraint = getConstraintForRelation(<TypeParameter>source);
// A type variable with no constraint is not related to the non-primitive object type.
if (constraint || !(target.flags & TypeFlags.NonPrimitive)) {
if (!constraint || constraint.flags & TypeFlags.Any) {
constraint = emptyObjectType;
}
// Report constraint errors only if the constraint is not the empty object type
const reportConstraintErrors = reportErrors && constraint !== emptyObjectType;
if (result = isRelatedTo(constraint, target, reportConstraintErrors)) {
const constraint = getConstraintForRelation(<TypeParameter>source);
if (!constraint || constraint.flags & TypeFlags.Any) {
// A type variable with no constraint is not related to the non-primitive object type.
if (result = isRelatedTo(emptyObjectType, extractTypesOfKind(target, ~TypeFlags.NonPrimitive))) {
errorInfo = saveErrorInfo;
return result;
}
}
else if (result = isRelatedTo(constraint, target, reportErrors)) {
errorInfo = saveErrorInfo;
return result;
}
}
else if (source.flags & TypeFlags.Index) {
if (result = isRelatedTo(keyofConstraintType, target, reportErrors)) {