Skip to content

Commit 1de8c65

Browse files
committed
Unconstrained type parameter not assignable to 'object'
1 parent 5ea4d3b commit 1de8c65

File tree

1 file changed

+8
-9
lines changed

1 file changed

+8
-9
lines changed

src/compiler/checker.ts

+8-9
Original file line numberDiff line numberDiff line change
@@ -10716,19 +10716,18 @@ namespace ts {
1071610716
return result;
1071710717
}
1071810718
}
10719-
let constraint = getConstraintForRelation(<TypeParameter>source);
10720-
// A type variable with no constraint is not related to the non-primitive object type.
10721-
if (constraint || !(target.flags & TypeFlags.NonPrimitive)) {
10722-
if (!constraint || constraint.flags & TypeFlags.Any) {
10723-
constraint = emptyObjectType;
10724-
}
10725-
// Report constraint errors only if the constraint is not the empty object type
10726-
const reportConstraintErrors = reportErrors && constraint !== emptyObjectType;
10727-
if (result = isRelatedTo(constraint, target, reportConstraintErrors)) {
10719+
const constraint = getConstraintForRelation(<TypeParameter>source);
10720+
if (!constraint || constraint.flags & TypeFlags.Any) {
10721+
// A type variable with no constraint is not related to the non-primitive object type.
10722+
if (result = isRelatedTo(emptyObjectType, extractTypesOfKind(target, ~TypeFlags.NonPrimitive))) {
1072810723
errorInfo = saveErrorInfo;
1072910724
return result;
1073010725
}
1073110726
}
10727+
else if (result = isRelatedTo(constraint, target, reportErrors)) {
10728+
errorInfo = saveErrorInfo;
10729+
return result;
10730+
}
1073210731
}
1073310732
else if (source.flags & TypeFlags.Index) {
1073410733
if (result = isRelatedTo(keyofConstraintType, target, reportErrors)) {

0 commit comments

Comments
 (0)