Skip to content

Commit d6d9dd7

Browse files
committed
Reorganize a bit
1 parent c44f1a4 commit d6d9dd7

File tree

2 files changed

+18
-17
lines changed

2 files changed

+18
-17
lines changed

src/compiler/checker.ts

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -14715,7 +14715,7 @@ namespace ts {
1471514715
}
1471614716
}
1471714717
else {
14718-
if (source.flags !== target.flags || source.flags & (TypeFlags.AnyOrUnknown | TypeFlags.Primitive | TypeFlags.NonPrimitive | TypeFlags.TypeParameter)) return false;
14718+
if (!(source.flags === target.flags && source.flags & TypeFlags.Substructure)) return false;
1471914719
}
1472014720
if (source.flags & TypeFlags.Object && target.flags & TypeFlags.Object) {
1472114721
const related = relation.get(getRelationKey(source, target, IntersectionState.None, relation));
@@ -15054,6 +15054,12 @@ namespace ts {
1505415054
let source = getNormalizedType(originalSource, /*writing*/ false);
1505515055
let target = getNormalizedType(originalTarget, /*writing*/ true);
1505615056

15057+
if (source === target) return Ternary.True;
15058+
15059+
if (relation === identityRelation) {
15060+
return isIdenticalTo(source, target);
15061+
}
15062+
1505715063
// Try to see if we're relating something like `Foo` -> `Bar | null | undefined`.
1505815064
// If so, reporting the `null` and `undefined` in the type is hardly useful.
1505915065
// First, see if we're even relating an object type to a union.
@@ -15067,17 +15073,11 @@ namespace ts {
1506715073
(target as UnionType).types.length <= 3 && maybeTypeOfKind(target, TypeFlags.Nullable)) {
1506815074
const nullStrippedTarget = extractTypesOfKind(target, ~TypeFlags.Nullable);
1506915075
if (!(nullStrippedTarget.flags & (TypeFlags.Union | TypeFlags.Never))) {
15076+
if (source === nullStrippedTarget) return Ternary.True;
1507015077
target = nullStrippedTarget;
1507115078
}
1507215079
}
1507315080

15074-
// both types are the same - covers 'they are the same primitive type or both are Any' or the same type parameter cases
15075-
if (source === target) return Ternary.True;
15076-
15077-
if (relation === identityRelation) {
15078-
return isIdenticalTo(source, target);
15079-
}
15080-
1508115081
if (relation === comparableRelation && !(target.flags & TypeFlags.Never) && isSimpleTypeRelatedTo(target, source, relation) ||
1508215082
isSimpleTypeRelatedTo(source, target, relation, reportErrors ? reportError : undefined)) return Ternary.True;
1508315083

@@ -15223,19 +15223,18 @@ namespace ts {
1522315223
}
1522415224

1522515225
function isIdenticalTo(source: Type, target: Type): Ternary {
15226-
let result: Ternary;
1522715226
const flags = source.flags & target.flags;
15228-
if (flags & TypeFlags.Object || flags & TypeFlags.IndexedAccess || flags & TypeFlags.Conditional || flags & TypeFlags.Index || flags & TypeFlags.Substitution) {
15229-
return recursiveTypeRelatedTo(source, target, /*reportErrors*/ false, IntersectionState.None);
15227+
if (!(flags & TypeFlags.Substructure)) {
15228+
return Ternary.False;
1523015229
}
15231-
if (flags & (TypeFlags.Union | TypeFlags.Intersection)) {
15232-
if (result = eachTypeRelatedToSomeType(<UnionOrIntersectionType>source, <UnionOrIntersectionType>target)) {
15233-
if (result &= eachTypeRelatedToSomeType(<UnionOrIntersectionType>target, <UnionOrIntersectionType>source)) {
15234-
return result;
15235-
}
15230+
if (flags & TypeFlags.UnionOrIntersection) {
15231+
let result = eachTypeRelatedToSomeType(<UnionOrIntersectionType>source, <UnionOrIntersectionType>target);
15232+
if (result) {
15233+
result &= eachTypeRelatedToSomeType(<UnionOrIntersectionType>target, <UnionOrIntersectionType>source);
1523615234
}
15235+
return result;
1523715236
}
15238-
return Ternary.False;
15237+
return recursiveTypeRelatedTo(source, target, /*reportErrors*/ false, IntersectionState.None);
1523915238
}
1524015239

1524115240
function getTypeOfPropertyInTypes(types: Type[], name: __String) {

src/compiler/types.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4318,6 +4318,8 @@ namespace ts {
43184318
ObjectFlagsType = Any | Nullable | Never | Object | Union | Intersection,
43194319
/* @internal */
43204320
Simplifiable = IndexedAccess | Conditional,
4321+
/* @internal */
4322+
Substructure = Object | Union | Intersection | Index | IndexedAccess | Conditional | Substitution,
43214323
// 'Narrowable' types are types where narrowing actually narrows.
43224324
// This *should* be every type other than null, undefined, void, and never
43234325
Narrowable = Any | Unknown | StructuredOrInstantiable | StringLike | NumberLike | BigIntLike | BooleanLike | ESSymbol | UniqueESSymbol | NonPrimitive,

0 commit comments

Comments
 (0)