@@ -1400,10 +1400,10 @@ namespace ts {
1400
1400
return resolveExternalModuleSymbol(node.parent.symbol, dontResolveAlias);
1401
1401
}
1402
1402
1403
- function getTargetOfExportSpecifier(node: ExportSpecifier, dontResolveAlias?: boolean): Symbol {
1404
- return (<ExportDeclaration> node.parent.parent) .moduleSpecifier ?
1405
- getExternalModuleMember(<ExportDeclaration> node.parent.parent, node, dontResolveAlias) :
1406
- resolveEntityName(node.propertyName || node.name, SymbolFlags.Value | SymbolFlags.Type | SymbolFlags.Namespace , /*ignoreErrors*/ false, dontResolveAlias);
1403
+ function getTargetOfExportSpecifier(node: ExportSpecifier, meaning: SymbolFlags, dontResolveAlias?: boolean) {
1404
+ return node.parent.parent.moduleSpecifier ?
1405
+ getExternalModuleMember(node.parent.parent, node, dontResolveAlias) :
1406
+ resolveEntityName(node.propertyName || node.name, meaning , /*ignoreErrors*/ false, dontResolveAlias);
1407
1407
}
1408
1408
1409
1409
function getTargetOfExportAssignment(node: ExportAssignment, dontResolveAlias: boolean): Symbol {
@@ -1421,7 +1421,7 @@ namespace ts {
1421
1421
case SyntaxKind.ImportSpecifier:
1422
1422
return getTargetOfImportSpecifier(<ImportSpecifier>node, dontRecursivelyResolve);
1423
1423
case SyntaxKind.ExportSpecifier:
1424
- return getTargetOfExportSpecifier(<ExportSpecifier>node, dontRecursivelyResolve);
1424
+ return getTargetOfExportSpecifier(<ExportSpecifier>node, SymbolFlags.Value | SymbolFlags.Type | SymbolFlags.Namespace, dontRecursivelyResolve);
1425
1425
case SyntaxKind.ExportAssignment:
1426
1426
return getTargetOfExportAssignment(<ExportAssignment>node, dontRecursivelyResolve);
1427
1427
case SyntaxKind.NamespaceExportDeclaration:
@@ -3721,10 +3721,7 @@ namespace ts {
3721
3721
exportSymbol = resolveName(node.parent, node.text, SymbolFlags.Value | SymbolFlags.Type | SymbolFlags.Namespace | SymbolFlags.Alias, Diagnostics.Cannot_find_name_0, node);
3722
3722
}
3723
3723
else if (node.parent.kind === SyntaxKind.ExportSpecifier) {
3724
- const exportSpecifier = <ExportSpecifier>node.parent;
3725
- exportSymbol = (<ExportDeclaration>exportSpecifier.parent.parent).moduleSpecifier ?
3726
- getExternalModuleMember(<ExportDeclaration>exportSpecifier.parent.parent, exportSpecifier) :
3727
- resolveEntityName(exportSpecifier.propertyName || exportSpecifier.name, SymbolFlags.Value | SymbolFlags.Type | SymbolFlags.Namespace | SymbolFlags.Alias);
3724
+ exportSymbol = getTargetOfExportSpecifier(<ExportSpecifier>node.parent, SymbolFlags.Value | SymbolFlags.Type | SymbolFlags.Namespace | SymbolFlags.Alias);
3728
3725
}
3729
3726
const result: Node[] = [];
3730
3727
if (exportSymbol) {
@@ -7257,7 +7254,7 @@ namespace ts {
7257
7254
accessExpression && checkThatExpressionIsProperSymbolReference(accessExpression.argumentExpression, indexType, /*reportError*/ false) ?
7258
7255
getPropertyNameForKnownSymbolName((<Identifier>(<PropertyAccessExpression>accessExpression.argumentExpression).name).text) :
7259
7256
undefined;
7260
- if (propName) {
7257
+ if (propName !== undefined ) {
7261
7258
const prop = getPropertyOfType(objectType, propName);
7262
7259
if (prop) {
7263
7260
if (accessExpression) {
@@ -9234,25 +9231,39 @@ namespace ts {
9234
9231
let result = Ternary.True;
9235
9232
const saveErrorInfo = errorInfo;
9236
9233
9237
- outer: for (const t of targetSignatures) {
9238
- // Only elaborate errors from the first failure
9239
- let shouldElaborateErrors = reportErrors;
9240
- for (const s of sourceSignatures) {
9241
- const related = signatureRelatedTo(s, t, shouldElaborateErrors);
9242
- if (related) {
9243
- result &= related;
9244
- errorInfo = saveErrorInfo;
9245
- continue outer;
9234
+ if (getObjectFlags(source) & ObjectFlags.Instantiated && getObjectFlags(target) & ObjectFlags.Instantiated && source.symbol === target.symbol) {
9235
+ // We instantiations of the same anonymous type (which typically will be the type of a method).
9236
+ // Simply do a pairwise comparison of the signatures in the two signature lists instead of the
9237
+ // much more expensive N * M comparison matrix we explore below.
9238
+ for (let i = 0; i < targetSignatures.length; i++) {
9239
+ const related = signatureRelatedTo(sourceSignatures[i], targetSignatures[i], reportErrors);
9240
+ if (!related) {
9241
+ return Ternary.False;
9246
9242
}
9247
- shouldElaborateErrors = false ;
9243
+ result &= related ;
9248
9244
}
9245
+ }
9246
+ else {
9247
+ outer: for (const t of targetSignatures) {
9248
+ // Only elaborate errors from the first failure
9249
+ let shouldElaborateErrors = reportErrors;
9250
+ for (const s of sourceSignatures) {
9251
+ const related = signatureRelatedTo(s, t, shouldElaborateErrors);
9252
+ if (related) {
9253
+ result &= related;
9254
+ errorInfo = saveErrorInfo;
9255
+ continue outer;
9256
+ }
9257
+ shouldElaborateErrors = false;
9258
+ }
9249
9259
9250
- if (shouldElaborateErrors) {
9251
- reportError(Diagnostics.Type_0_provides_no_match_for_the_signature_1,
9252
- typeToString(source),
9253
- signatureToString(t, /*enclosingDeclaration*/ undefined, /*flags*/ undefined, kind));
9260
+ if (shouldElaborateErrors) {
9261
+ reportError(Diagnostics.Type_0_provides_no_match_for_the_signature_1,
9262
+ typeToString(source),
9263
+ signatureToString(t, /*enclosingDeclaration*/ undefined, /*flags*/ undefined, kind));
9264
+ }
9265
+ return Ternary.False;
9254
9266
}
9255
- return Ternary.False;
9256
9267
}
9257
9268
return result;
9258
9269
}
@@ -13243,6 +13254,8 @@ namespace ts {
13243
13254
let attributesTable = createMap<Symbol>();
13244
13255
let spread: Type = emptyObjectType;
13245
13256
let attributesArray: Symbol[] = [];
13257
+ let hasSpreadAnyType = false;
13258
+
13246
13259
for (const attributeDecl of attributes.properties) {
13247
13260
const member = attributeDecl.symbol;
13248
13261
if (isJsxAttribute(attributeDecl)) {
@@ -13271,31 +13284,33 @@ namespace ts {
13271
13284
const exprType = checkExpression(attributeDecl.expression);
13272
13285
if (!isValidSpreadType(exprType)) {
13273
13286
error(attributeDecl, Diagnostics.Spread_types_may_only_be_created_from_object_types);
13274
- return anyType ;
13287
+ hasSpreadAnyType = true ;
13275
13288
}
13276
13289
if (isTypeAny(exprType)) {
13277
- return anyType ;
13290
+ hasSpreadAnyType = true ;
13278
13291
}
13279
13292
spread = getSpreadType(spread, exprType);
13280
13293
}
13281
13294
}
13282
13295
13283
- if (spread !== emptyObjectType) {
13284
- if (attributesArray.length > 0) {
13285
- spread = getSpreadType(spread, createJsxAttributesType(attributes.symbol, attributesTable));
13286
- attributesArray = [];
13287
- attributesTable = createMap<Symbol>();
13296
+ if (!hasSpreadAnyType) {
13297
+ if (spread !== emptyObjectType) {
13298
+ if (attributesArray.length > 0) {
13299
+ spread = getSpreadType(spread, createJsxAttributesType(attributes.symbol, attributesTable));
13300
+ attributesArray = [];
13301
+ attributesTable = createMap<Symbol>();
13302
+ }
13303
+ attributesArray = getPropertiesOfType(spread);
13288
13304
}
13289
- attributesArray = getPropertiesOfType(spread);
13290
- }
13291
13305
13292
- attributesTable = createMap<Symbol>();
13293
- if (attributesArray) {
13294
- forEach(attributesArray, (attr) => {
13295
- if (!filter || filter(attr)) {
13296
- attributesTable.set(attr.name, attr);
13297
- }
13298
- });
13306
+ attributesTable = createMap<Symbol>();
13307
+ if (attributesArray) {
13308
+ forEach(attributesArray, (attr) => {
13309
+ if (!filter || filter(attr)) {
13310
+ attributesTable.set(attr.name, attr);
13311
+ }
13312
+ });
13313
+ }
13299
13314
}
13300
13315
13301
13316
// Handle children attribute
@@ -13319,7 +13334,7 @@ namespace ts {
13319
13334
// Error if there is a attribute named "children" and children element.
13320
13335
// This is because children element will overwrite the value from attributes
13321
13336
const jsxChildrenPropertyName = getJsxElementChildrenPropertyname();
13322
- if (jsxChildrenPropertyName && jsxChildrenPropertyName !== "") {
13337
+ if (!hasSpreadAnyType && jsxChildrenPropertyName && jsxChildrenPropertyName !== "") {
13323
13338
if (attributesTable.has(jsxChildrenPropertyName)) {
13324
13339
error(attributes, Diagnostics._0_are_specified_twice_The_attribute_named_0_will_be_overwritten, jsxChildrenPropertyName);
13325
13340
}
@@ -13333,7 +13348,7 @@ namespace ts {
13333
13348
}
13334
13349
}
13335
13350
13336
- return createJsxAttributesType(attributes.symbol, attributesTable);
13351
+ return hasSpreadAnyType ? anyType : createJsxAttributesType(attributes.symbol, attributesTable);
13337
13352
13338
13353
/**
13339
13354
* Create anonymous type from given attributes symbol table.
@@ -13429,7 +13444,18 @@ namespace ts {
13429
13444
}
13430
13445
}
13431
13446
13432
- return getUnionType(map(signatures, getReturnTypeOfSignature), /*subtypeReduction*/ true);
13447
+ const instantiatedSignatures = [];
13448
+ for (const signature of signatures) {
13449
+ if (signature.typeParameters) {
13450
+ const typeArguments = fillMissingTypeArguments(/*typeArguments*/ undefined, signature.typeParameters, /*minTypeArgumentCount*/ 0);
13451
+ instantiatedSignatures.push(getSignatureInstantiation(signature, typeArguments));
13452
+ }
13453
+ else {
13454
+ instantiatedSignatures.push(signature);
13455
+ }
13456
+ }
13457
+
13458
+ return getUnionType(map(instantiatedSignatures, getReturnTypeOfSignature), /*subtypeReduction*/ true);
13433
13459
}
13434
13460
13435
13461
/**
0 commit comments