@@ -7434,8 +7434,8 @@ namespace ts {
7434
7434
function isSubtypeOfAny(source: Type, targets: Type[]): boolean {
7435
7435
for (const target of targets) {
7436
7436
if (source !== target && isTypeSubtypeOf(source, target) && (
7437
- !(getObjectFlags(source) & ( ObjectFlags.ClassOrInterface | ObjectFlags.Reference) ) ||
7438
- !(getObjectFlags(target) & ( ObjectFlags.ClassOrInterface | ObjectFlags.Reference) ) ||
7437
+ !(getObjectFlags(getTargetType( source)) & ObjectFlags.Class ) ||
7438
+ !(getObjectFlags(getTargetType( target)) & ObjectFlags.Class ) ||
7439
7439
isTypeDerivedFrom(source, target))) {
7440
7440
return true;
7441
7441
}
@@ -9605,7 +9605,7 @@ namespace ts {
9605
9605
if (relation === identityRelation) {
9606
9606
return propertiesIdenticalTo(source, target);
9607
9607
}
9608
- const requireOptionalProperties = relation === subtypeRelation && !isObjectLiteralType(source);
9608
+ const requireOptionalProperties = relation === subtypeRelation && !isObjectLiteralType(source) && !isEmptyArrayLiteralType(source) ;
9609
9609
const unmatchedProperty = getUnmatchedProperty(source, target, requireOptionalProperties);
9610
9610
if (unmatchedProperty) {
9611
9611
if (reportErrors) {
@@ -10313,6 +10313,11 @@ namespace ts {
10313
10313
!(type.flags & TypeFlags.Nullable) && isTypeAssignableTo(type, anyReadonlyArrayType);
10314
10314
}
10315
10315
10316
+ function isEmptyArrayLiteralType(type: Type): boolean {
10317
+ const elementType = isArrayType(type) ? (<TypeReference>type).typeArguments[0] : undefined;
10318
+ return elementType === undefinedWideningType || elementType === neverType;
10319
+ }
10320
+
10316
10321
function isTupleLikeType(type: Type): boolean {
10317
10322
return !!getPropertyOfType(type, "0" as __String);
10318
10323
}
@@ -13878,7 +13883,6 @@ namespace ts {
13878
13883
type.pattern = node;
13879
13884
return type;
13880
13885
}
13881
- const contextualType = getApparentTypeOfContextualType(node);
13882
13886
if (contextualType && contextualTypeIsTupleLikeType(contextualType)) {
13883
13887
const pattern = contextualType.pattern;
13884
13888
// If array literal is contextually typed by a binding pattern or an assignment pattern, pad the resulting
@@ -18066,14 +18070,6 @@ namespace ts {
18066
18070
return (target.flags & TypeFlags.Nullable) !== 0 || isTypeComparableTo(source, target);
18067
18071
}
18068
18072
18069
- function getBestChoiceType(type1: Type, type2: Type): Type {
18070
- const firstAssignableToSecond = isTypeAssignableTo(type1, type2);
18071
- const secondAssignableToFirst = isTypeAssignableTo(type2, type1);
18072
- return secondAssignableToFirst && !firstAssignableToSecond ? type1 :
18073
- firstAssignableToSecond && !secondAssignableToFirst ? type2 :
18074
- getUnionType([type1, type2], /*subtypeReduction*/ true);
18075
- }
18076
-
18077
18073
function checkBinaryExpression(node: BinaryExpression, checkMode?: CheckMode) {
18078
18074
return checkBinaryLikeExpression(node.left, node.operatorToken, node.right, checkMode, node);
18079
18075
}
@@ -18210,7 +18206,7 @@ namespace ts {
18210
18206
leftType;
18211
18207
case SyntaxKind.BarBarToken:
18212
18208
return getTypeFacts(leftType) & TypeFacts.Falsy ?
18213
- getBestChoiceType( removeDefinitelyFalsyTypes(leftType), rightType) :
18209
+ getUnionType([ removeDefinitelyFalsyTypes(leftType), rightType], /*subtypeReduction*/ true ) :
18214
18210
leftType;
18215
18211
case SyntaxKind.EqualsToken:
18216
18212
checkAssignmentOperator(rightType);
@@ -18370,7 +18366,7 @@ namespace ts {
18370
18366
checkExpression(node.condition);
18371
18367
const type1 = checkExpression(node.whenTrue, checkMode);
18372
18368
const type2 = checkExpression(node.whenFalse, checkMode);
18373
- return getBestChoiceType( type1, type2);
18369
+ return getUnionType([ type1, type2], /*subtypeReduction*/ true );
18374
18370
}
18375
18371
18376
18372
function checkTemplateExpression(node: TemplateExpression): Type {
0 commit comments