@@ -1400,10 +1400,10 @@ namespace ts {
14001400 return resolveExternalModuleSymbol(node.parent.symbol, dontResolveAlias);
14011401 }
14021402
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);
14071407 }
14081408
14091409 function getTargetOfExportAssignment(node: ExportAssignment, dontResolveAlias: boolean): Symbol {
@@ -1421,7 +1421,7 @@ namespace ts {
14211421 case SyntaxKind.ImportSpecifier:
14221422 return getTargetOfImportSpecifier(<ImportSpecifier>node, dontRecursivelyResolve);
14231423 case SyntaxKind.ExportSpecifier:
1424- return getTargetOfExportSpecifier(<ExportSpecifier>node, dontRecursivelyResolve);
1424+ return getTargetOfExportSpecifier(<ExportSpecifier>node, SymbolFlags.Value | SymbolFlags.Type | SymbolFlags.Namespace, dontRecursivelyResolve);
14251425 case SyntaxKind.ExportAssignment:
14261426 return getTargetOfExportAssignment(<ExportAssignment>node, dontRecursivelyResolve);
14271427 case SyntaxKind.NamespaceExportDeclaration:
@@ -3721,10 +3721,7 @@ namespace ts {
37213721 exportSymbol = resolveName(node.parent, node.text, SymbolFlags.Value | SymbolFlags.Type | SymbolFlags.Namespace | SymbolFlags.Alias, Diagnostics.Cannot_find_name_0, node);
37223722 }
37233723 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);
37283725 }
37293726 const result: Node[] = [];
37303727 if (exportSymbol) {
@@ -7257,7 +7254,7 @@ namespace ts {
72577254 accessExpression && checkThatExpressionIsProperSymbolReference(accessExpression.argumentExpression, indexType, /*reportError*/ false) ?
72587255 getPropertyNameForKnownSymbolName((<Identifier>(<PropertyAccessExpression>accessExpression.argumentExpression).name).text) :
72597256 undefined;
7260- if (propName) {
7257+ if (propName !== undefined ) {
72617258 const prop = getPropertyOfType(objectType, propName);
72627259 if (prop) {
72637260 if (accessExpression) {
@@ -9234,25 +9231,39 @@ namespace ts {
92349231 let result = Ternary.True;
92359232 const saveErrorInfo = errorInfo;
92369233
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;
92469242 }
9247- shouldElaborateErrors = false ;
9243+ result &= related ;
92489244 }
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+ }
92499259
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;
92549266 }
9255- return Ternary.False;
92569267 }
92579268 return result;
92589269 }
@@ -13243,6 +13254,8 @@ namespace ts {
1324313254 let attributesTable = createMap<Symbol>();
1324413255 let spread: Type = emptyObjectType;
1324513256 let attributesArray: Symbol[] = [];
13257+ let hasSpreadAnyType = false;
13258+
1324613259 for (const attributeDecl of attributes.properties) {
1324713260 const member = attributeDecl.symbol;
1324813261 if (isJsxAttribute(attributeDecl)) {
@@ -13271,31 +13284,33 @@ namespace ts {
1327113284 const exprType = checkExpression(attributeDecl.expression);
1327213285 if (!isValidSpreadType(exprType)) {
1327313286 error(attributeDecl, Diagnostics.Spread_types_may_only_be_created_from_object_types);
13274- return anyType ;
13287+ hasSpreadAnyType = true ;
1327513288 }
1327613289 if (isTypeAny(exprType)) {
13277- return anyType ;
13290+ hasSpreadAnyType = true ;
1327813291 }
1327913292 spread = getSpreadType(spread, exprType);
1328013293 }
1328113294 }
1328213295
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);
1328813304 }
13289- attributesArray = getPropertiesOfType(spread);
13290- }
1329113305
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+ }
1329913314 }
1330013315
1330113316 // Handle children attribute
@@ -13319,7 +13334,7 @@ namespace ts {
1331913334 // Error if there is a attribute named "children" and children element.
1332013335 // This is because children element will overwrite the value from attributes
1332113336 const jsxChildrenPropertyName = getJsxElementChildrenPropertyname();
13322- if (jsxChildrenPropertyName && jsxChildrenPropertyName !== "") {
13337+ if (!hasSpreadAnyType && jsxChildrenPropertyName && jsxChildrenPropertyName !== "") {
1332313338 if (attributesTable.has(jsxChildrenPropertyName)) {
1332413339 error(attributes, Diagnostics._0_are_specified_twice_The_attribute_named_0_will_be_overwritten, jsxChildrenPropertyName);
1332513340 }
@@ -13333,7 +13348,7 @@ namespace ts {
1333313348 }
1333413349 }
1333513350
13336- return createJsxAttributesType(attributes.symbol, attributesTable);
13351+ return hasSpreadAnyType ? anyType : createJsxAttributesType(attributes.symbol, attributesTable);
1333713352
1333813353 /**
1333913354 * Create anonymous type from given attributes symbol table.
@@ -13429,7 +13444,18 @@ namespace ts {
1342913444 }
1343013445 }
1343113446
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);
1343313459 }
1343413460
1343513461 /**
0 commit comments