mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-02-16 15:44:16 -06:00
Properly handle Object and Function types
This commit is contained in:
parent
2a30aaff2f
commit
81326ac901
@ -8571,14 +8571,16 @@ namespace ts {
|
||||
// An object type S is considered to be derived from an object type T if
|
||||
// S is a union type and every constituent of S is derived from T,
|
||||
// T is a union type and S is derived from at least one constituent of T, or
|
||||
// T is one of the global types Object and Function and S is a subtype of T, or
|
||||
// T occurs directly or indirectly in an 'extends' clause of S.
|
||||
// Note that this check ignores type parameters and only considers the
|
||||
// inheritance hierarchy.
|
||||
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)) :
|
||||
target === globalObjectType || target === globalFunctionType ? isTypeSubtypeOf(source, target) :
|
||||
hasBaseType(source, getTargetType(target));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This is *not* a bi-directional relationship.
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user