@@ -14706,11 +14706,17 @@ namespace ts {
14706
14706
if (isFreshLiteralType(target)) {
14707
14707
target = (<FreshableType>target).regularType;
14708
14708
}
14709
- if (source === target ||
14710
- relation === comparableRelation && !(target.flags & TypeFlags.Never) && isSimpleTypeRelatedTo(target, source, relation) ||
14711
- relation !== identityRelation && isSimpleTypeRelatedTo(source, target, relation)) {
14709
+ if (source === target) {
14712
14710
return true;
14713
14711
}
14712
+ if (relation !== identityRelation) {
14713
+ if (relation === comparableRelation && !(target.flags & TypeFlags.Never) && isSimpleTypeRelatedTo(target, source, relation) || isSimpleTypeRelatedTo(source, target, relation)) {
14714
+ return true;
14715
+ }
14716
+ }
14717
+ else {
14718
+ if (!(source.flags === target.flags && source.flags & TypeFlags.Substructure)) return false;
14719
+ }
14714
14720
if (source.flags & TypeFlags.Object && target.flags & TypeFlags.Object) {
14715
14721
const related = relation.get(getRelationKey(source, target, IntersectionState.None, relation));
14716
14722
if (related !== undefined) {
@@ -15048,6 +15054,12 @@ namespace ts {
15048
15054
let source = getNormalizedType(originalSource, /*writing*/ false);
15049
15055
let target = getNormalizedType(originalTarget, /*writing*/ true);
15050
15056
15057
+ if (source === target) return Ternary.True;
15058
+
15059
+ if (relation === identityRelation) {
15060
+ return isIdenticalTo(source, target);
15061
+ }
15062
+
15051
15063
// Try to see if we're relating something like `Foo` -> `Bar | null | undefined`.
15052
15064
// If so, reporting the `null` and `undefined` in the type is hardly useful.
15053
15065
// First, see if we're even relating an object type to a union.
@@ -15061,17 +15073,11 @@ namespace ts {
15061
15073
(target as UnionType).types.length <= 3 && maybeTypeOfKind(target, TypeFlags.Nullable)) {
15062
15074
const nullStrippedTarget = extractTypesOfKind(target, ~TypeFlags.Nullable);
15063
15075
if (!(nullStrippedTarget.flags & (TypeFlags.Union | TypeFlags.Never))) {
15076
+ if (source === nullStrippedTarget) return Ternary.True;
15064
15077
target = nullStrippedTarget;
15065
15078
}
15066
15079
}
15067
15080
15068
- // both types are the same - covers 'they are the same primitive type or both are Any' or the same type parameter cases
15069
- if (source === target) return Ternary.True;
15070
-
15071
- if (relation === identityRelation) {
15072
- return isIdenticalTo(source, target);
15073
- }
15074
-
15075
15081
if (relation === comparableRelation && !(target.flags & TypeFlags.Never) && isSimpleTypeRelatedTo(target, source, relation) ||
15076
15082
isSimpleTypeRelatedTo(source, target, relation, reportErrors ? reportError : undefined)) return Ternary.True;
15077
15083
@@ -15217,19 +15223,18 @@ namespace ts {
15217
15223
}
15218
15224
15219
15225
function isIdenticalTo(source: Type, target: Type): Ternary {
15220
- let result: Ternary;
15221
15226
const flags = source.flags & target.flags;
15222
- if (flags & TypeFlags.Object || flags & TypeFlags.IndexedAccess || flags & TypeFlags.Conditional || flags & TypeFlags.Index || flags & TypeFlags.Substitution ) {
15223
- return recursiveTypeRelatedTo(source, target, /*reportErrors*/ false, IntersectionState.None) ;
15227
+ if (!( flags & TypeFlags.Substructure) ) {
15228
+ return Ternary.False ;
15224
15229
}
15225
- if (flags & (TypeFlags.Union | TypeFlags.Intersection)) {
15226
- if (result = eachTypeRelatedToSomeType(<UnionOrIntersectionType>source, <UnionOrIntersectionType>target)) {
15227
- if (result &= eachTypeRelatedToSomeType(<UnionOrIntersectionType>target, <UnionOrIntersectionType>source)) {
15228
- return result;
15229
- }
15230
+ if (flags & TypeFlags.UnionOrIntersection) {
15231
+ let result = eachTypeRelatedToSomeType(<UnionOrIntersectionType>source, <UnionOrIntersectionType>target);
15232
+ if (result) {
15233
+ result &= eachTypeRelatedToSomeType(<UnionOrIntersectionType>target, <UnionOrIntersectionType>source);
15230
15234
}
15235
+ return result;
15231
15236
}
15232
- return Ternary.False ;
15237
+ return recursiveTypeRelatedTo(source, target, /*reportErrors*/ false, IntersectionState.None) ;
15233
15238
}
15234
15239
15235
15240
function getTypeOfPropertyInTypes(types: Type[], name: __String) {
@@ -18390,7 +18395,7 @@ namespace ts {
18390
18395
}
18391
18396
18392
18397
function isTypeOrBaseIdenticalTo(s: Type, t: Type) {
18393
- return isTypeIdenticalTo(s, t) || !!(s.flags & ( TypeFlags.StringLiteral | TypeFlags.NumberLiteral)) && isTypeIdenticalTo(getBaseTypeOfLiteralType(s), t );
18398
+ return isTypeIdenticalTo(s, t) || !!(t.flags & TypeFlags.String && s.flags & TypeFlags.StringLiteral || t.flags & TypeFlags.Number && s.flags & TypeFlags.NumberLiteral );
18394
18399
}
18395
18400
18396
18401
function isTypeCloselyMatchedBy(s: Type, t: Type) {
0 commit comments