@@ -1436,10 +1436,10 @@ namespace ts {
1436
1436
return resolveExternalModuleSymbol(node.parent.symbol, dontResolveAlias);
1437
1437
}
1438
1438
1439
- function getTargetOfExportSpecifier(node: ExportSpecifier, dontResolveAlias?: boolean): Symbol {
1440
- return (<ExportDeclaration> node.parent.parent) .moduleSpecifier ?
1441
- getExternalModuleMember(<ExportDeclaration> node.parent.parent, node, dontResolveAlias) :
1442
- resolveEntityName(node.propertyName || node.name, SymbolFlags.Value | SymbolFlags.Type | SymbolFlags.Namespace , /*ignoreErrors*/ false, dontResolveAlias);
1439
+ function getTargetOfExportSpecifier(node: ExportSpecifier, meaning: SymbolFlags, dontResolveAlias?: boolean) {
1440
+ return node.parent.parent.moduleSpecifier ?
1441
+ getExternalModuleMember(node.parent.parent, node, dontResolveAlias) :
1442
+ resolveEntityName(node.propertyName || node.name, meaning , /*ignoreErrors*/ false, dontResolveAlias);
1443
1443
}
1444
1444
1445
1445
function getTargetOfExportAssignment(node: ExportAssignment, dontResolveAlias: boolean): Symbol {
@@ -1457,7 +1457,7 @@ namespace ts {
1457
1457
case SyntaxKind.ImportSpecifier:
1458
1458
return getTargetOfImportSpecifier(<ImportSpecifier>node, dontRecursivelyResolve);
1459
1459
case SyntaxKind.ExportSpecifier:
1460
- return getTargetOfExportSpecifier(<ExportSpecifier>node, dontRecursivelyResolve);
1460
+ return getTargetOfExportSpecifier(<ExportSpecifier>node, SymbolFlags.Value | SymbolFlags.Type | SymbolFlags.Namespace, dontRecursivelyResolve);
1461
1461
case SyntaxKind.ExportAssignment:
1462
1462
return getTargetOfExportAssignment(<ExportAssignment>node, dontRecursivelyResolve);
1463
1463
case SyntaxKind.NamespaceExportDeclaration:
@@ -3757,10 +3757,7 @@ namespace ts {
3757
3757
exportSymbol = resolveName(node.parent, node.text, SymbolFlags.Value | SymbolFlags.Type | SymbolFlags.Namespace | SymbolFlags.Alias, Diagnostics.Cannot_find_name_0, node);
3758
3758
}
3759
3759
else if (node.parent.kind === SyntaxKind.ExportSpecifier) {
3760
- const exportSpecifier = <ExportSpecifier>node.parent;
3761
- exportSymbol = (<ExportDeclaration>exportSpecifier.parent.parent).moduleSpecifier ?
3762
- getExternalModuleMember(<ExportDeclaration>exportSpecifier.parent.parent, exportSpecifier) :
3763
- resolveEntityName(exportSpecifier.propertyName || exportSpecifier.name, SymbolFlags.Value | SymbolFlags.Type | SymbolFlags.Namespace | SymbolFlags.Alias);
3760
+ exportSymbol = getTargetOfExportSpecifier(<ExportSpecifier>node.parent, SymbolFlags.Value | SymbolFlags.Type | SymbolFlags.Namespace | SymbolFlags.Alias);
3764
3761
}
3765
3762
const result: Node[] = [];
3766
3763
if (exportSymbol) {
@@ -7293,7 +7290,7 @@ namespace ts {
7293
7290
accessExpression && checkThatExpressionIsProperSymbolReference(accessExpression.argumentExpression, indexType, /*reportError*/ false) ?
7294
7291
getPropertyNameForKnownSymbolName((<Identifier>(<PropertyAccessExpression>accessExpression.argumentExpression).name).text) :
7295
7292
undefined;
7296
- if (propName) {
7293
+ if (propName !== undefined ) {
7297
7294
const prop = getPropertyOfType(objectType, propName);
7298
7295
if (prop) {
7299
7296
if (accessExpression) {
@@ -9264,25 +9261,39 @@ namespace ts {
9264
9261
let result = Ternary.True;
9265
9262
const saveErrorInfo = errorInfo;
9266
9263
9267
- outer: for (const t of targetSignatures) {
9268
- // Only elaborate errors from the first failure
9269
- let shouldElaborateErrors = reportErrors;
9270
- for (const s of sourceSignatures) {
9271
- const related = signatureRelatedTo(s, t, shouldElaborateErrors);
9272
- if (related) {
9273
- result &= related;
9274
- errorInfo = saveErrorInfo;
9275
- continue outer;
9264
+ if (getObjectFlags(source) & ObjectFlags.Instantiated && getObjectFlags(target) & ObjectFlags.Instantiated && source.symbol === target.symbol) {
9265
+ // We instantiations of the same anonymous type (which typically will be the type of a method).
9266
+ // Simply do a pairwise comparison of the signatures in the two signature lists instead of the
9267
+ // much more expensive N * M comparison matrix we explore below.
9268
+ for (let i = 0; i < targetSignatures.length; i++) {
9269
+ const related = signatureRelatedTo(sourceSignatures[i], targetSignatures[i], reportErrors);
9270
+ if (!related) {
9271
+ return Ternary.False;
9276
9272
}
9277
- shouldElaborateErrors = false ;
9273
+ result &= related ;
9278
9274
}
9275
+ }
9276
+ else {
9277
+ outer: for (const t of targetSignatures) {
9278
+ // Only elaborate errors from the first failure
9279
+ let shouldElaborateErrors = reportErrors;
9280
+ for (const s of sourceSignatures) {
9281
+ const related = signatureRelatedTo(s, t, shouldElaborateErrors);
9282
+ if (related) {
9283
+ result &= related;
9284
+ errorInfo = saveErrorInfo;
9285
+ continue outer;
9286
+ }
9287
+ shouldElaborateErrors = false;
9288
+ }
9279
9289
9280
- if (shouldElaborateErrors) {
9281
- reportError(Diagnostics.Type_0_provides_no_match_for_the_signature_1,
9282
- typeToString(source),
9283
- signatureToString(t, /*enclosingDeclaration*/ undefined, /*flags*/ undefined, kind));
9290
+ if (shouldElaborateErrors) {
9291
+ reportError(Diagnostics.Type_0_provides_no_match_for_the_signature_1,
9292
+ typeToString(source),
9293
+ signatureToString(t, /*enclosingDeclaration*/ undefined, /*flags*/ undefined, kind));
9294
+ }
9295
+ return Ternary.False;
9284
9296
}
9285
- return Ternary.False;
9286
9297
}
9287
9298
return result;
9288
9299
}
@@ -13273,6 +13284,8 @@ namespace ts {
13273
13284
let attributesTable = createMap<Symbol>();
13274
13285
let spread: Type = emptyObjectType;
13275
13286
let attributesArray: Symbol[] = [];
13287
+ let hasSpreadAnyType = false;
13288
+
13276
13289
for (const attributeDecl of attributes.properties) {
13277
13290
const member = attributeDecl.symbol;
13278
13291
if (isJsxAttribute(attributeDecl)) {
@@ -13301,31 +13314,33 @@ namespace ts {
13301
13314
const exprType = checkExpression(attributeDecl.expression);
13302
13315
if (!isValidSpreadType(exprType)) {
13303
13316
error(attributeDecl, Diagnostics.Spread_types_may_only_be_created_from_object_types);
13304
- return anyType ;
13317
+ hasSpreadAnyType = true ;
13305
13318
}
13306
13319
if (isTypeAny(exprType)) {
13307
- return anyType ;
13320
+ hasSpreadAnyType = true ;
13308
13321
}
13309
13322
spread = getSpreadType(spread, exprType);
13310
13323
}
13311
13324
}
13312
13325
13313
- if (spread !== emptyObjectType) {
13314
- if (attributesArray.length > 0) {
13315
- spread = getSpreadType(spread, createJsxAttributesType(attributes.symbol, attributesTable));
13316
- attributesArray = [];
13317
- attributesTable = createMap<Symbol>();
13326
+ if (!hasSpreadAnyType) {
13327
+ if (spread !== emptyObjectType) {
13328
+ if (attributesArray.length > 0) {
13329
+ spread = getSpreadType(spread, createJsxAttributesType(attributes.symbol, attributesTable));
13330
+ attributesArray = [];
13331
+ attributesTable = createMap<Symbol>();
13332
+ }
13333
+ attributesArray = getPropertiesOfType(spread);
13318
13334
}
13319
- attributesArray = getPropertiesOfType(spread);
13320
- }
13321
13335
13322
- attributesTable = createMap<Symbol>();
13323
- if (attributesArray) {
13324
- forEach(attributesArray, (attr) => {
13325
- if (!filter || filter(attr)) {
13326
- attributesTable.set(attr.name, attr);
13327
- }
13328
- });
13336
+ attributesTable = createMap<Symbol>();
13337
+ if (attributesArray) {
13338
+ forEach(attributesArray, (attr) => {
13339
+ if (!filter || filter(attr)) {
13340
+ attributesTable.set(attr.name, attr);
13341
+ }
13342
+ });
13343
+ }
13329
13344
}
13330
13345
13331
13346
// Handle children attribute
@@ -13349,7 +13364,7 @@ namespace ts {
13349
13364
// Error if there is a attribute named "children" and children element.
13350
13365
// This is because children element will overwrite the value from attributes
13351
13366
const jsxChildrenPropertyName = getJsxElementChildrenPropertyname();
13352
- if (jsxChildrenPropertyName && jsxChildrenPropertyName !== "") {
13367
+ if (!hasSpreadAnyType && jsxChildrenPropertyName && jsxChildrenPropertyName !== "") {
13353
13368
if (attributesTable.has(jsxChildrenPropertyName)) {
13354
13369
error(attributes, Diagnostics._0_are_specified_twice_The_attribute_named_0_will_be_overwritten, jsxChildrenPropertyName);
13355
13370
}
@@ -13363,7 +13378,7 @@ namespace ts {
13363
13378
}
13364
13379
}
13365
13380
13366
- return createJsxAttributesType(attributes.symbol, attributesTable);
13381
+ return hasSpreadAnyType ? anyType : createJsxAttributesType(attributes.symbol, attributesTable);
13367
13382
13368
13383
/**
13369
13384
* Create anonymous type from given attributes symbol table.
0 commit comments