mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-02-05 16:38:05 -06:00
Elaborate on the first non-array type when object literals are compared against 'T | T[]'.
This commit is contained in:
parent
36e26c1a35
commit
649f294413
@ -11182,7 +11182,8 @@ namespace ts {
|
||||
if (reportErrors) {
|
||||
const bestMatchingType =
|
||||
findMatchingDiscriminantType(source, target) ||
|
||||
findMatchingTypeReferenceOrTypeAliasReference(source, target);
|
||||
findMatchingTypeReferenceOrTypeAliasReference(source, target) ||
|
||||
findBestTypeForObjectLiteral(source, target);
|
||||
|
||||
isRelatedTo(source, bestMatchingType || targetTypes[targetTypes.length - 1], /*reportErrors*/ true);
|
||||
}
|
||||
@ -11207,6 +11208,11 @@ namespace ts {
|
||||
}
|
||||
}
|
||||
|
||||
function findBestTypeForObjectLiteral(source: Type, unionTarget: UnionOrIntersectionType) {
|
||||
if (getObjectFlags(source) & ObjectFlags.ObjectLiteral && forEachType(unionTarget, isArrayLikeType)) {
|
||||
return find(unionTarget.types, t => !isArrayLikeType(t));
|
||||
}
|
||||
}
|
||||
|
||||
// Keep this up-to-date with the same logic within `getApparentTypeOfContextualType`, since they should behave similarly
|
||||
function findMatchingDiscriminantType(source: Type, target: UnionOrIntersectionType) {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user