Merge branch 'master' into fix10193

This commit is contained in:
Kanchalai Tanglertsampan
2016-08-09 15:58:30 -07:00
7 changed files with 664 additions and 13 deletions

View File

@@ -5924,6 +5924,13 @@ namespace ts {
return isTypeRelatedTo(source, target, assignableRelation);
}
// A type S is considered to be an instance of a type T if S and T are the same type or if S is a
// subtype of T but not structurally identical to T. This specifically means that two distinct but
// structurally identical types (such as two classes) are not considered instances of each other.
function isTypeInstanceOf(source: Type, target: Type): boolean {
return source === target || isTypeSubtypeOf(source, target) && !isTypeIdenticalTo(source, target);
}
/**
* This is *not* a bi-directional relationship.
* If one needs to check both directions for comparability, use a second call to this function or 'checkTypeComparableTo'.
@@ -8575,12 +8582,12 @@ namespace ts {
function getNarrowedType(type: Type, candidate: Type, assumeTrue: boolean) {
if (!assumeTrue) {
return filterType(type, t => !isTypeSubtypeOf(t, candidate));
return filterType(type, t => !isTypeInstanceOf(t, candidate));
}
// If the current type is a union type, remove all constituents that aren't assignable to
// If the current type is a union type, remove all constituents that couldn't be instances of
// the candidate type. If one or more constituents remain, return a union of those.
if (type.flags & TypeFlags.Union) {
const assignableConstituents = filter((<UnionType>type).types, t => isTypeAssignableTo(t, candidate));
const assignableConstituents = filter((<UnionType>type).types, t => isTypeInstanceOf(t, candidate));
if (assignableConstituents.length) {
return getUnionType(assignableConstituents);
}