| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent c44f1a4 commit d6d9dd7
2 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -14715,7 +14715,7 @@ namespace ts { | |||
| 14715 | 14715 | } | |
| 14716 | 14716 | } | |
| 14717 | 14717 | 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; | ||
| 14719 | 14719 | } | |
| 14720 | 14720 | if (source.flags & TypeFlags.Object && target.flags & TypeFlags.Object) { | |
| 14721 | 14721 | const related = relation.get(getRelationKey(source, target, IntersectionState.None, relation)); | |
@@ -15054,6 +15054,12 @@ namespace ts { | |||
| 15054 | 15054 | let source = getNormalizedType(originalSource, /*writing*/ false); | |
| 15055 | 15055 | let target = getNormalizedType(originalTarget, /*writing*/ true); | |
| 15056 | 15056 | ||
| 15057 | + if (source === target) return Ternary.True; | ||
| 15058 | + | ||
| 15059 | + if (relation === identityRelation) { | ||
| 15060 | + return isIdenticalTo(source, target); | ||
| 15061 | + } | ||
| 15062 | + | ||
| 15057 | 15063 | // Try to see if we're relating something like `Foo` -> `Bar | null | undefined`. | |
| 15058 | 15064 | // If so, reporting the `null` and `undefined` in the type is hardly useful. | |
| 15059 | 15065 | // First, see if we're even relating an object type to a union. | |
@@ -15067,17 +15073,11 @@ namespace ts { | |||
| 15067 | 15073 | (target as UnionType).types.length <= 3 && maybeTypeOfKind(target, TypeFlags.Nullable)) { | |
| 15068 | 15074 | const nullStrippedTarget = extractTypesOfKind(target, ~TypeFlags.Nullable); | |
| 15069 | 15075 | if (!(nullStrippedTarget.flags & (TypeFlags.Union | TypeFlags.Never))) { | |
| 15076 | + if (source === nullStrippedTarget) return Ternary.True; | ||
| 15070 | 15077 | target = nullStrippedTarget; | |
| 15071 | 15078 | } | |
| 15072 | 15079 | } | |
| 15073 | 15080 | ||
| 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 | - | ||
| 15081 | 15081 | if (relation === comparableRelation && !(target.flags & TypeFlags.Never) && isSimpleTypeRelatedTo(target, source, relation) || | |
| 15082 | 15082 | isSimpleTypeRelatedTo(source, target, relation, reportErrors ? reportError : undefined)) return Ternary.True; | |
| 15083 | 15083 | ||
@@ -15223,19 +15223,18 @@ namespace ts { | |||
| 15223 | 15223 | } | |
| 15224 | 15224 | ||
| 15225 | 15225 | function isIdenticalTo(source: Type, target: Type): Ternary { | |
| 15226 | - let result: Ternary; | ||
| 15227 | 15226 | 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; | ||
| 15230 | 15229 | } | |
| 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); | ||
| 15236 | 15234 | } | |
| 15235 | + return result; | ||
| 15237 | 15236 | } | |
| 15238 | - return Ternary.False; | ||
| 15237 | + return recursiveTypeRelatedTo(source, target, /*reportErrors*/ false, IntersectionState.None); | ||
| 15239 | 15238 | } | |
| 15240 | 15239 | ||
| 15241 | 15240 | function getTypeOfPropertyInTypes(types: Type[], name: __String) { | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -4318,6 +4318,8 @@ namespace ts { | |||
| 4318 | 4318 | ObjectFlagsType = Any | Nullable | Never | Object | Union | Intersection, | |
| 4319 | 4319 | /* @internal */ | |
| 4320 | 4320 | Simplifiable = IndexedAccess | Conditional, | |
| 4321 | + /* @internal */ | ||
| 4322 | + Substructure = Object | Union | Intersection | Index | IndexedAccess | Conditional | Substitution, | ||
| 4321 | 4323 | // 'Narrowable' types are types where narrowing actually narrows. | |
| 4322 | 4324 | // This *should* be every type other than null, undefined, void, and never | |
| 4323 | 4325 | Narrowable = Any | Unknown | StructuredOrInstantiable | StringLike | NumberLike | BigIntLike | BooleanLike | ESSymbol | UniqueESSymbol | NonPrimitive, | |
| Back | FazBrowse Home | New Git URL |
0 commit comments