@@ -15764,23 +15764,13 @@ namespace ts {
15764
15764
}
15765
15765
}
15766
15766
15767
- if (isLiteralType(source) && !typeCouldHaveNoTopLevelSingletonTypes (target)) {
15767
+ if (isLiteralType(source) && !typeCouldHaveTopLevelSingletonTypes (target)) {
15768
15768
generalizedSourceType = getTypeNameForErrorDisplay(getBaseTypeOfLiteralType(source));
15769
15769
}
15770
15770
15771
15771
reportError(message, generalizedSourceType, targetType);
15772
15772
}
15773
15773
15774
- function typeCouldHaveNoTopLevelSingletonTypes(type: Type) {
15775
- return forEachType(type, typeCouldHaveNoTopLevelSingletonTypesWorker);
15776
- }
15777
-
15778
- function typeCouldHaveNoTopLevelSingletonTypesWorker(type: Type): boolean {
15779
- return (type.flags & TypeFlags.Intersection)
15780
- ? !!forEach((type as IntersectionType).types, typeCouldHaveNoTopLevelSingletonTypesWorker)
15781
- : isUnitType(type) || !!(type.flags & TypeFlags.Instantiable);
15782
- }
15783
-
15784
15774
function tryElaborateErrorsForPrimitivesAndObjects(source: Type, target: Type) {
15785
15775
const sourceType = symbolValueDeclarationIsContextSensitive(source.symbol) ? typeToString(source, source.symbol.valueDeclaration) : typeToString(source);
15786
15776
const targetType = symbolValueDeclarationIsContextSensitive(target.symbol) ? typeToString(target, target.symbol.valueDeclaration) : typeToString(target);
@@ -17375,6 +17365,21 @@ namespace ts {
17375
17365
}
17376
17366
}
17377
17367
17368
+ function typeCouldHaveTopLevelSingletonTypes(type: Type): boolean {
17369
+ if (type.flags & TypeFlags.UnionOrIntersection) {
17370
+ return !!forEach((type as IntersectionType).types, typeCouldHaveTopLevelSingletonTypes);
17371
+ }
17372
+
17373
+ if (type.flags & TypeFlags.Instantiable) {
17374
+ const constraint = getConstraintOfType(type);
17375
+ if (constraint) {
17376
+ return typeCouldHaveTopLevelSingletonTypes(constraint);
17377
+ }
17378
+ }
17379
+
17380
+ return isUnitType(type);
17381
+ }
17382
+
17378
17383
function getBestMatchingType(source: Type, target: UnionOrIntersectionType, isRelatedTo = compareTypesAssignable) {
17379
17384
return findMatchingDiscriminantType(source, target, isRelatedTo, /*skipPartial*/ true) ||
17380
17385
findMatchingTypeReferenceOrTypeAliasReference(source, target) ||
0 commit comments