Replace subtype check in derivedness check with flags and structure checks (#27403)

* Replace subtype check in derivedness check with flags and structure checks

* Remove now extraneous clause
This commit is contained in:
Wesley Wigham
2018-10-04 12:55:39 -07:00
committed by GitHub
parent 62306bc3f9
commit f07404938f
5 changed files with 259 additions and 3 deletions

View File

@@ -10616,9 +10616,9 @@ namespace ts {
function isTypeDerivedFrom(source: Type, target: Type): boolean {
return source.flags & TypeFlags.Union ? every((<UnionType>source).types, t => isTypeDerivedFrom(t, target)) :
target.flags & TypeFlags.Union ? some((<UnionType>target).types, t => isTypeDerivedFrom(source, t)) :
source.flags & TypeFlags.Primitive && !(target.flags & TypeFlags.Primitive) ? false :
source.flags & TypeFlags.InstantiableNonPrimitive ? isTypeDerivedFrom(getBaseConstraintOfType(source) || emptyObjectType, target) :
target === globalObjectType || target === globalFunctionType ? isTypeSubtypeOf(source, target) :
target === globalObjectType ? !!(source.flags & (TypeFlags.Object | TypeFlags.NonPrimitive)) :
target === globalFunctionType ? isFunctionObjectType(source as ObjectType) :
hasBaseType(source, getTargetType(target));
}
@@ -15371,7 +15371,7 @@ namespace ts {
// Check that right operand is a function type with a prototype property
const rightType = getTypeOfExpression(expr.right);
if (!isTypeSubtypeOf(rightType, globalFunctionType)) {
if (!isTypeDerivedFrom(rightType, globalFunctionType)) {
return type;
}