From 1de8c656784e77768f39b876682aa0328ce8ee08 Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Tue, 1 May 2018 12:38:29 -0700 Subject: [PATCH] Unconstrained type parameter not assignable to 'object' --- src/compiler/checker.ts | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index d825b0d9717..dfb1a4c8c4e 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -10716,19 +10716,18 @@ namespace ts { return result; } } - let constraint = getConstraintForRelation(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(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)) {