@@ -16782,7 +16782,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
16782
16782
// a subtype of just `A` or just `B`. When we encounter such a type parameter, we therefore check if the
16783
16783
// type parameter is a subtype of a union of all the other types.
16784
16784
if (source.flags & TypeFlags.TypeParameter && getBaseConstraintOrType(source).flags & TypeFlags.Union) {
16785
- if (isTypeRelatedTo (source, getUnionType(map(types, t => t === source ? neverType : t)), strictSubtypeRelation )) {
16785
+ if (isTypeStrictSubtypeOf (source, getUnionType(map(types, t => t === source ? neverType : t)))) {
16786
16786
orderedRemoveItemAt(types, i);
16787
16787
}
16788
16788
continue;
@@ -16816,7 +16816,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
16816
16816
}
16817
16817
}
16818
16818
if (
16819
- isTypeRelatedTo (source, target, strictSubtypeRelation ) && (
16819
+ isTypeStrictSubtypeOf (source, target) && (
16820
16820
!(getObjectFlags(getTargetType(source)) & ObjectFlags.Class) ||
16821
16821
!(getObjectFlags(getTargetType(target)) & ObjectFlags.Class) ||
16822
16822
isTypeDerivedFrom(source, target)
@@ -28042,7 +28042,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
28042
28042
// the constituent based on its type facts. We use the strict subtype relation because it treats `object`
28043
28043
// as a subtype of `{}`, and we need the type facts check because function types are subtypes of `object`,
28044
28044
// but are classified as "function" according to `typeof`.
28045
- isTypeRelatedTo (t, impliedType, strictSubtypeRelation ) ? hasTypeFacts(t, facts) ? t : neverType :
28045
+ isTypeStrictSubtypeOf (t, impliedType) ? hasTypeFacts(t, facts) ? t : neverType :
28046
28046
// We next check if the consituent is a supertype of the implied type. If so, we substitute the implied
28047
28047
// type. This handles top types like `unknown` and `{}`, and supertypes like `{ toString(): string }`.
28048
28048
isTypeSubtypeOf(impliedType, t) ? impliedType :
@@ -28240,7 +28240,26 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
28240
28240
matching || type,
28241
28241
checkDerived ?
28242
28242
t => isTypeDerivedFrom(t, c) ? t : isTypeDerivedFrom(c, t) ? c : neverType :
28243
- t => isTypeStrictSubtypeOf(t, c) ? t : isTypeStrictSubtypeOf(c, t) ? c : isTypeSubtypeOf(t, c) ? t : isTypeSubtypeOf(c, t) ? c : neverType,
28243
+ t => {
28244
+ // isTypeStrictSubtypeOf(t, c) ? t : isTypeStrictSubtypeOf(c, t) ? c : isTypeSubtypeOf(t, c) ? t : isTypeSubtypeOf(c, t) ? c : neverType;
28245
+
28246
+ if (t.flags & TypeFlags.Literal && c.flags & TypeFlags.Literal) {
28247
+ if (t.flags & TypeFlags.BooleanLiteral && c.flags & TypeFlags.BooleanLiteral) {
28248
+ return t === c ? t : neverType;
28249
+ }
28250
+ return (t as LiteralType).value === (c as LiteralType).value ? t : neverType;
28251
+ }
28252
+
28253
+ if (isTypeStrictSubtypeOf(t, c)) return t;
28254
+ if (isTypeStrictSubtypeOf(c, t)) return c;
28255
+
28256
+ if (t.flags & TypeFlags.Unit && c.flags & TypeFlags.Unit) return neverType;
28257
+
28258
+ if (isTypeSubtypeOf(t, c)) return t;
28259
+ if (isTypeSubtypeOf(c, t)) return c;
28260
+
28261
+ return neverType;
28262
+ },
28244
28263
);
28245
28264
// If no constituents are directly related, create intersections for any generic constituents that
28246
28265
// are related by constraint.
@@ -28257,6 +28276,17 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
28257
28276
getIntersectionType([type, candidate]);
28258
28277
}
28259
28278
28279
+ // function strictSubtypeImpliesSubtype(source: Type, target: Type) {
28280
+ // const s = source.flags;
28281
+ // const t = target.flags;
28282
+ // if (
28283
+ // !(t & TypeFlags.Unknown && !(s & TypeFlags.Any))
28284
+ // || !(s & TypeFlags.Object && t & TypeFlags.NonPrimitive && !(isEmptyAnonymousObjectType(source) && !(getObjectFlags(source) & ObjectFlags.FreshLiteral)))
28285
+ // ) return false;
28286
+
28287
+ // return true;
28288
+ // }
28289
+
28260
28290
function narrowTypeByCallExpression(type: Type, callExpression: CallExpression, assumeTrue: boolean): Type {
28261
28291
if (hasMatchingArgument(callExpression, reference)) {
28262
28292
const signature = assumeTrue || !isCallChain(callExpression) ? getEffectsSignature(callExpression) : undefined;
0 commit comments