@@ -1453,6 +1453,12 @@ namespace ts {
14531453 location = location.parent;
14541454 }
14551455 break;
1456+ case SyntaxKind.JSDocTypedefTag:
1457+ case SyntaxKind.JSDocCallbackTag:
1458+ // js type aliases do not resolve names from their host, so skip past it
1459+ lastLocation = location;
1460+ location = getJSDocHost(location).parent;
1461+ continue;
14561462 }
14571463 if (isSelfReferenceLocation(location)) {
14581464 lastSelfReferenceLocation = location;
@@ -2153,25 +2159,31 @@ namespace ts {
21532159 */
21542160 function resolveEntityNameFromJSSpecialAssignment(name: Identifier, meaning: SymbolFlags) {
21552161 if (isJSDocTypeReference(name.parent)) {
2156- const host = getJSDocHost(name.parent);
2157- if (host) {
2158- const secondaryLocation = getJSSpecialAssignmentSymbol(getJSDocHost(name.parent.parent.parent as JSDocTag));
2159- return secondaryLocation && resolveName(secondaryLocation, name.escapedText, meaning, /*nameNotFoundMessage*/ undefined, name, /*isUse*/ true);
2162+ const secondaryLocation = getJSSpecialAssignmentLocation(name.parent);
2163+ if (secondaryLocation) {
2164+ return resolveName(secondaryLocation, name.escapedText, meaning, /*nameNotFoundMessage*/ undefined, name, /*isUse*/ true);
21602165 }
21612166 }
21622167 }
21632168
2164- function getJSSpecialAssignmentSymbol(host: HasJSDoc ): Declaration | undefined {
2165- if (isPropertyAssignment(host) && isFunctionLike(host.initializer)) {
2166- const symbol = getSymbolOfNode(host.initializer);
2167- return symbol && symbol.valueDeclaration ;
2169+ function getJSSpecialAssignmentLocation(node: TypeReferenceNode ): Declaration | undefined {
2170+ const typeAlias = findAncestor(node, node => !(isJSDocNode(node) || node.flags & NodeFlags.JSDoc) ? "quit" : isJSDocTypeAlias(node));
2171+ if (typeAlias) {
2172+ return;
21682173 }
2169- else if (isExpressionStatement(host) &&
2170- isBinaryExpression(host.expression) &&
2171- getSpecialPropertyAssignmentKind(host.expression) === SpecialPropertyAssignmentKind.PrototypeProperty) {
2174+ const host = getJSDocHost(node);
2175+ if (host &&
2176+ isExpressionStatement(host) &&
2177+ isBinaryExpression(host.expression) &&
2178+ getSpecialPropertyAssignmentKind(host.expression) === SpecialPropertyAssignmentKind.PrototypeProperty) {
21722179 const symbol = getSymbolOfNode(host.expression.left);
21732180 return symbol && symbol.parent.valueDeclaration;
21742181 }
2182+ const sig = getHostSignatureFromJSDocHost(host);
2183+ if (sig) {
2184+ const symbol = getSymbolOfNode(sig);
2185+ return symbol && symbol.valueDeclaration;
2186+ }
21752187 }
21762188
21772189 function resolveExternalModuleName(location: Node, moduleReferenceExpression: Expression): Symbol {
@@ -9554,7 +9566,16 @@ namespace ts {
95549566 // parameters that are in scope (and therefore potentially referenced). For type literals that
95559567 // aren't the right hand side of a generic type alias declaration we optimize by reducing the
95569568 // set of type parameters to those that are possibly referenced in the literal.
9557- const declaration = symbol.declarations[0];
9569+ let declaration = symbol.declarations[0];
9570+ if (isInJavaScriptFile(declaration)) {
9571+ const paramTag = findAncestor(declaration, isJSDocParameterTag);
9572+ if (paramTag) {
9573+ const paramSymbol = getParameterSymbolFromJSDoc(paramTag);
9574+ if (paramSymbol) {
9575+ declaration = paramSymbol.valueDeclaration;
9576+ }
9577+ }
9578+ }
95589579 let outerTypeParameters = getOuterTypeParameters(declaration, /*includeThisTypes*/ true);
95599580 if (isJavaScriptConstructor(declaration)) {
95609581 const templateTagParameters = getTypeParametersFromDeclaration(declaration as DeclarationWithTypeParameters);
0 commit comments