From 0a4f5013609578467c5bc0be7385e089e6867223 Mon Sep 17 00:00:00 2001 From: Jake Bailey <5341706+jakebailey@users.noreply.github.com> Date: Fri, 13 Nov 2026 19:12:49 -0800 Subject: [PATCH 1/2] Align JSDoc AST contracts with parser-produced children JSDoc signatures contain documentation tags rather than ordinary declaration children. Qualified JSDoc names also use namespace bodies that can end in an identifier. Describe these forms in the schema and generated public contracts. Keep native storage inheritance separate from public inheritance, and preserve union element types when generating readonly arrays. --- packages/typescript/src/ast/ast.generated.ts | 7 +- .../typescript/src/ast/factory.generated.ts | 4 +- packages/typescript/src/ast/is.generated.ts | 2 +- .../typescript/src/ast/visitor.generated.ts | 3 +- packages/typescript/test/sync/ast.test.ts | 65 +++++++++++++++++++ tools/scripts/tsc/ast.json | 23 +++++-- tools/scripts/tsc/ast.schema.json | 7 ++ tools/scripts/tsc/generate-ts-ast.ts | 4 +- tools/scripts/tsc/schema.ts | 4 +- tsc/internal/ast/ast_generated.go | 6 +- 10 files changed, 109 insertions(+), 16 deletions(-) diff --git a/packages/typescript/src/ast/ast.generated.ts b/packages/typescript/src/ast/ast.generated.ts index b808d79358d97..9f2e21e2ae760 100644 --- a/packages/typescript/src/ast/ast.generated.ts +++ b/packages/typescript/src/ast/ast.generated.ts @@ -1270,8 +1270,11 @@ export interface JSDocTypedefTag extends JSDocTagBase { readonly typeExpression?: Node; readonly name?: JSDocFullName; } -export interface JSDocSignature extends JSDocTypeBase, DeclarationBase, FunctionLikeBase { +export interface JSDocSignature extends JSDocTypeBase, DeclarationBase { readonly kind: SyntaxKind.JSDocSignature; + readonly typeParameters?: NodeArray; + readonly parameters: NodeArray; + readonly type?: JSDocReturnTag; } export interface JSDocNameReference extends TypeNodeBase { readonly kind: SyntaxKind.JSDocNameReference; @@ -1360,7 +1363,7 @@ export type DeclarationName = Identifier | PrivateIdentifier | StringLiteral | N export type ModuleName = Identifier | StringLiteral; export type ModuleExportName = Identifier | StringLiteral; export type PropertyName = Identifier | StringLiteral | NoSubstitutionTemplateLiteral | NumericLiteral | ComputedPropertyName | PrivateIdentifier | BigIntLiteral; -export type ModuleBody = ModuleBlock | ModuleDeclaration; +export type ModuleBody = ModuleBlock | ModuleDeclaration | Identifier; export type JSDocFullName = Identifier | ModuleDeclaration; export type ForInitializer = Expression | MissingDeclaration | VariableDeclarationList; export type ModuleReference = Identifier | QualifiedName | ExternalModuleReference; diff --git a/packages/typescript/src/ast/factory.generated.ts b/packages/typescript/src/ast/factory.generated.ts index d121803d683ad..5183a315d18e2 100644 --- a/packages/typescript/src/ast/factory.generated.ts +++ b/packages/typescript/src/ast/factory.generated.ts @@ -5219,7 +5219,7 @@ export function createJSDocTypedefTag(tagName: Identifier, typeExpression?: Node }) as unknown as JSDocTypedefTag; } -export function createJSDocSignature(typeParameters: readonly TypeParameterDeclaration[] | undefined, parameters: readonly ParameterDeclaration[], type?: TypeNode): JSDocSignature { +export function createJSDocSignature(typeParameters: readonly JSDocTemplateTag[] | undefined, parameters: readonly (JSDocParameterTag | JSDocThisTag)[], type?: JSDocReturnTag): JSDocSignature { return new NodeObject(SyntaxKind.JSDocSignature, { typeParameters: typeParameters ? createNodeArray(typeParameters) : undefined, parameters: createNodeArray(parameters), @@ -5991,7 +5991,7 @@ export function updateJSDocTypedefTag(node: JSDocTypedefTag, tagName: Identifier return node.tagName !== tagName || node.typeExpression !== typeExpression || node.name !== name || node.comment !== comment ? createJSDocTypedefTag(tagName, typeExpression, name, comment) : node; } -export function updateJSDocSignature(node: JSDocSignature, typeParameters: readonly TypeParameterDeclaration[] | undefined, parameters: readonly ParameterDeclaration[], type?: TypeNode): JSDocSignature { +export function updateJSDocSignature(node: JSDocSignature, typeParameters: readonly JSDocTemplateTag[] | undefined, parameters: readonly (JSDocParameterTag | JSDocThisTag)[], type?: JSDocReturnTag): JSDocSignature { return node.typeParameters !== typeParameters || node.parameters !== parameters || node.type !== type ? createJSDocSignature(typeParameters, parameters, type) : node; } diff --git a/packages/typescript/src/ast/is.generated.ts b/packages/typescript/src/ast/is.generated.ts index 2ba2f1da7bff2..dc1034c048217 100644 --- a/packages/typescript/src/ast/is.generated.ts +++ b/packages/typescript/src/ast/is.generated.ts @@ -2171,7 +2171,7 @@ export declare namespace isPropertyName { isPropertyName.Handle = isPropertyName as any; export function isModuleBody(node: Node): node is ModuleBody { - return node.kind === SyntaxKind.ModuleBlock || node.kind === SyntaxKind.ModuleDeclaration; + return node.kind === SyntaxKind.ModuleBlock || node.kind === SyntaxKind.ModuleDeclaration || node.kind === SyntaxKind.Identifier; } export declare namespace isModuleBody { diff --git a/packages/typescript/src/ast/visitor.generated.ts b/packages/typescript/src/ast/visitor.generated.ts index 520f2ddcd8522..c5c63fe50e2e9 100644 --- a/packages/typescript/src/ast/visitor.generated.ts +++ b/packages/typescript/src/ast/visitor.generated.ts @@ -374,6 +374,7 @@ import { isImportAttributes, isImportClause, isJSDocFullName, + isJSDocReturnTag, isJsxAttributeName, isJsxAttributes, isJsxAttributeValue, @@ -1337,7 +1338,7 @@ const visitEachChildTable: Record = { [SyntaxKind.JSDocSignature]: (node: JSDocSignature, visitor: Visitor): JSDocSignature => { const _typeParameters = visitNodes(node.typeParameters, visitor); const _parameters = visitNodes(node.parameters, visitor); - const _type = visitNode(node.type, visitor, isTypeNode); + const _type = visitNode(node.type, visitor, isJSDocReturnTag); return updateJSDocSignature(node, _typeParameters, _parameters, _type); }, [SyntaxKind.JSDocNameReference]: (node: JSDocNameReference, visitor: Visitor): JSDocNameReference => { diff --git a/packages/typescript/test/sync/ast.test.ts b/packages/typescript/test/sync/ast.test.ts index e848d7b7f5143..d3e33409b6cbf 100644 --- a/packages/typescript/test/sync/ast.test.ts +++ b/packages/typescript/test/sync/ast.test.ts @@ -123,6 +123,71 @@ test("index signatures allow an omitted type", () => { }); describe("AST property contracts", { concurrency }, () => { + test("JSDoc signatures expose tags rather than declaration children", () => { + using api = spawnAPI(); + const source = api.createSourceFile( + "/callback.js", + `/** + * @callback Callback + * @this {Object} + * @param {string} value + * @returns {number} + */ +function f() {} +`, + ).sourceFile; + const declaration = source.statements.find(astModule.isFunctionDeclaration); + assert.ok(declaration); + const doc = declaration.jsDoc?.[0]; + assert.ok(doc && astModule.isJSDoc(doc)); + const callback = doc.tags?.[0]; + assert.ok(callback && astModule.isJSDocCallbackTag(callback)); + const signature = callback.typeExpression; + assert.ok(astModule.isJSDocSignature(signature)); + const parameters: astModule.NodeArray = signature.parameters; + const result: astModule.JSDocReturnTag | undefined = signature.type; + assert.strictEqual(parameters[0].kind, SyntaxKind.JSDocThisTag); + assert.strictEqual(parameters[1].kind, SyntaxKind.JSDocParameterTag); + assert.strictEqual(result?.kind, SyntaxKind.JSDocReturnTag); + assert.strictEqual(visitEachChild(signature, node => node), signature); + + const template = factory.createJSDocTemplateTag(factory.createIdentifier("template"), undefined, []); + const typeParameters: readonly astModule.JSDocTemplateTag[] = [template]; + const synthesized = factory.createJSDocSignature(typeParameters, parameters, result); + const clone = getSynthesizedDeepClone(synthesized); + assert.strictEqual(clone.typeParameters?.[0].kind, SyntaxKind.JSDocTemplateTag); + assert.deepStrictEqual(clone.parameters.map(parameter => parameter.kind), [SyntaxKind.JSDocThisTag, SyntaxKind.JSDocParameterTag]); + assert.strictEqual(clone.type?.kind, SyntaxKind.JSDocReturnTag); + assert.strictEqual(visitEachChild(clone, node => node), clone); + assert.strictEqual(visitEachChild(synthesized, node => node), synthesized); + }); + + test("JSDoc namespace bodies include their final identifier", () => { + using api = spawnAPI(); + const source = api.createSourceFile( + "/namespace.js", + `/** @typedef {string} Outer.Inner.Value */ +function f() {} +`, + ).sourceFile; + const declaration = source.statements.find(astModule.isFunctionDeclaration); + assert.ok(declaration); + const doc = declaration.jsDoc?.[0]; + assert.ok(doc && astModule.isJSDoc(doc)); + const tag = doc.tags?.[0]; + assert.ok(tag && astModule.isJSDocTypedefTag(tag)); + const outer = tag.name; + assert.ok(outer && astModule.isModuleDeclaration(outer)); + const inner = outer.body; + assert.ok(inner && astModule.isModuleDeclaration(inner)); + const body: astModule.ModuleBody = factory.createIdentifier("Value"); + assert.ok(astModule.isModuleBody(body)); + assert.ok(inner.body && astModule.isIdentifier(inner.body)); + assert.strictEqual(inner.body.text, "Value"); + assert.strictEqual(visitEachChild(inner, node => node), inner); + assert.deepStrictEqual(collectKinds(getSynthesizedDeepClone(outer)), collectKinds(outer)); + }); + test("absent parser children have optional types", () => { const absent: { exportType: astModule.ExportAssignment["type"]; diff --git a/tools/scripts/tsc/ast.json b/tools/scripts/tsc/ast.json index b79180fd41fd2..3cfeb89d6b775 100644 --- a/tools/scripts/tsc/ast.json +++ b/tools/scripts/tsc/ast.json @@ -4764,18 +4764,32 @@ "DeclarationBase", "FunctionLikeBase" ], + "tsExtends": [ + "JSDocTypeBase", + "DeclarationBase" + ], "members": [ { "name": "TypeParameters", - "inherited": true + "inherited": true, + "type": "JSDocTemplateTag", + "list": "NodeList", + "optional": true }, { "name": "Parameters", - "inherited": true + "inherited": true, + "type": [ + "JSDocParameterTag", + "JSDocThisTag" + ], + "list": "NodeList" }, { "name": "Type", - "inherited": true + "inherited": true, + "type": "JSDocReturnTag", + "optional": true } ] }, @@ -5228,7 +5242,8 @@ ], "ModuleBody": [ "ModuleBlock", - "ModuleDeclaration" + "ModuleDeclaration", + "Identifier" ], "JSDocFullName": [ "Identifier", diff --git a/tools/scripts/tsc/ast.schema.json b/tools/scripts/tsc/ast.schema.json index ae08f0ac65a8a..011defc90360e 100644 --- a/tools/scripts/tsc/ast.schema.json +++ b/tools/scripts/tsc/ast.schema.json @@ -283,6 +283,13 @@ "type": "string" } }, + "tsExtends": { + "type": "array", + "description": "Public TypeScript bases when they differ from the native bases.", + "items": { + "type": "string" + } + }, "members": { "type": "array", "description": "Ordered list of members. Array position defines factory parameter order, visitor traversal order, and binary encoding order.", diff --git a/tools/scripts/tsc/generate-ts-ast.ts b/tools/scripts/tsc/generate-ts-ast.ts index 07615cf3181ee..c9f0d6661afc4 100644 --- a/tools/scripts/tsc/generate-ts-ast.ts +++ b/tools/scripts/tsc/generate-ts-ast.ts @@ -152,7 +152,7 @@ function resolveBaseExtends(base: NodeType): string { } function deriveNodeTsExtends(node: NodeType): string { - const tsExts = expandTsExtends(node.extendsKeys) + const tsExts = expandTsExtends(node.def?.tsExtends ?? node.extendsKeys) .map(e => baseTsName(e)); return tsExts.length > 0 ? tsExts.join(", ") : "Node"; } @@ -610,7 +610,7 @@ function generateFactory(): string { // ── Collect all types referenced in factory ── function addType(t: string) { // Extract base type names from complex types - const stripped = t.replace(/readonly\s+/g, "").replace(/\[\]/g, "") + const stripped = t.replace(/readonly\s+/g, "").replace(/\[\]/g, "").replace(/[()]/g, "") .replace(/NodeArray<(.+)>/g, "$1").replace(/\s*\|\s*/g, "|"); for (const part of stripped.split("|")) { const clean = part.trim(); diff --git a/tools/scripts/tsc/schema.ts b/tools/scripts/tsc/schema.ts index eb48ac6a1d919..ae5e2b107d6d3 100644 --- a/tools/scripts/tsc/schema.ts +++ b/tools/scripts/tsc/schema.ts @@ -27,6 +27,8 @@ export interface Member { export interface NodeDef { kind?: string | string[]; extends: string[]; + /** Public bases can differ from native bases used only for shared storage. */ + tsExtends?: string[]; members?: Member[]; generateSubtreeFacts?: boolean; arena?: boolean; @@ -548,7 +550,7 @@ export class ListType extends TypeBase { formatTypeScript(): string { const elementType = this.elementType.formatTypeScript(); if (this.listKind === "raw") { - return `readonly ${elementType}[]`; + return `readonly ${this.elementType.kind === "union" ? `(${elementType})` : elementType}[]`; } return `NodeArray<${elementType}>`; } diff --git a/tsc/internal/ast/ast_generated.go b/tsc/internal/ast/ast_generated.go index 97f5edd987b8e..556d6485209ba 100644 --- a/tsc/internal/ast/ast_generated.go +++ b/tsc/internal/ast/ast_generated.go @@ -532,7 +532,7 @@ type ( ModuleName = Node // Identifier | StringLiteral ModuleExportName = Node // Identifier | StringLiteral PropertyName = Node // Identifier | StringLiteral | NoSubstitutionTemplateLiteral | NumericLiteral | ComputedPropertyName | PrivateIdentifier | BigIntLiteral - ModuleBody = Node // ModuleBlock | ModuleDeclaration + ModuleBody = Node // ModuleBlock | ModuleDeclaration | Identifier JSDocFullName = Node // Identifier | ModuleDeclaration ForInitializer = Node // Expression | MissingDeclaration | VariableDeclarationList ModuleReference = Node // Identifier | QualifiedName | ExternalModuleReference @@ -8061,7 +8061,7 @@ type JSDocSignature struct { FunctionLikeBase } -func (f *NodeFactory) NewJSDocSignature(typeParameters *TypeParameterList, parameters *ParameterList, typeNode *TypeNode) *Node { +func (f *NodeFactory) NewJSDocSignature(typeParameters *NodeList, parameters *NodeList, typeNode *JSDocReturnTagNode) *Node { data := &JSDocSignature{} data.TypeParameters = typeParameters data.Parameters = parameters @@ -8069,7 +8069,7 @@ func (f *NodeFactory) NewJSDocSignature(typeParameters *TypeParameterList, param return f.newNode(KindJSDocSignature, data.AsNode()) } -func (f *NodeFactory) UpdateJSDocSignature(node *JSDocSignature, typeParameters *TypeParameterList, parameters *ParameterList, typeNode *TypeNode) *Node { +func (f *NodeFactory) UpdateJSDocSignature(node *JSDocSignature, typeParameters *NodeList, parameters *NodeList, typeNode *JSDocReturnTagNode) *Node { if typeParameters != node.TypeParameters || parameters != node.Parameters || typeNode != node.Type { return updateNode(f.NewJSDocSignature(typeParameters, parameters, typeNode), node.AsNode(), f.hooks) } From cc40e9dd74c1e46cc9875b83fddc6ea574556473 Mon Sep 17 00:00:00 2001 From: Jake Bailey <5341706+jakebailey@users.noreply.github.com> Date: Mon, 16 Nov 2026 17:26:18 -0800 Subject: [PATCH 2/2] Give JSDoc signatures their own fields JSDoc signatures borrowed function-like storage, so their tag children were reachable through accessors typed for parameter and type-parameter declarations. The public API then needed separate TypeScript bases to describe the real children. Nothing binds or checks these signatures as functions; the reparser converts them into real signature nodes. Declaring the tag fields directly lets the native and public shapes agree, so the separate TypeScript bases go away. --- tools/scripts/tsc/ast.json | 8 -------- tools/scripts/tsc/ast.schema.json | 7 ------- tools/scripts/tsc/generate-ts-ast.ts | 2 +- tools/scripts/tsc/schema.ts | 2 -- tsc/internal/ast/ast_generated.go | 18 ++++++------------ tsc/internal/ast/utilities.go | 1 - tsc/internal/parser/reparser.go | 6 +++--- 7 files changed, 10 insertions(+), 34 deletions(-) diff --git a/tools/scripts/tsc/ast.json b/tools/scripts/tsc/ast.json index 3cfeb89d6b775..36f4b7faae541 100644 --- a/tools/scripts/tsc/ast.json +++ b/tools/scripts/tsc/ast.json @@ -4760,25 +4760,18 @@ }, "JSDocSignature": { "extends": [ - "JSDocTypeBase", - "DeclarationBase", - "FunctionLikeBase" - ], - "tsExtends": [ "JSDocTypeBase", "DeclarationBase" ], "members": [ { "name": "TypeParameters", - "inherited": true, "type": "JSDocTemplateTag", "list": "NodeList", "optional": true }, { "name": "Parameters", - "inherited": true, "type": [ "JSDocParameterTag", "JSDocThisTag" @@ -4787,7 +4780,6 @@ }, { "name": "Type", - "inherited": true, "type": "JSDocReturnTag", "optional": true } diff --git a/tools/scripts/tsc/ast.schema.json b/tools/scripts/tsc/ast.schema.json index 011defc90360e..ae08f0ac65a8a 100644 --- a/tools/scripts/tsc/ast.schema.json +++ b/tools/scripts/tsc/ast.schema.json @@ -283,13 +283,6 @@ "type": "string" } }, - "tsExtends": { - "type": "array", - "description": "Public TypeScript bases when they differ from the native bases.", - "items": { - "type": "string" - } - }, "members": { "type": "array", "description": "Ordered list of members. Array position defines factory parameter order, visitor traversal order, and binary encoding order.", diff --git a/tools/scripts/tsc/generate-ts-ast.ts b/tools/scripts/tsc/generate-ts-ast.ts index c9f0d6661afc4..7aef579c62b06 100644 --- a/tools/scripts/tsc/generate-ts-ast.ts +++ b/tools/scripts/tsc/generate-ts-ast.ts @@ -152,7 +152,7 @@ function resolveBaseExtends(base: NodeType): string { } function deriveNodeTsExtends(node: NodeType): string { - const tsExts = expandTsExtends(node.def?.tsExtends ?? node.extendsKeys) + const tsExts = expandTsExtends(node.extendsKeys) .map(e => baseTsName(e)); return tsExts.length > 0 ? tsExts.join(", ") : "Node"; } diff --git a/tools/scripts/tsc/schema.ts b/tools/scripts/tsc/schema.ts index ae5e2b107d6d3..c3253a8abff48 100644 --- a/tools/scripts/tsc/schema.ts +++ b/tools/scripts/tsc/schema.ts @@ -27,8 +27,6 @@ export interface Member { export interface NodeDef { kind?: string | string[]; extends: string[]; - /** Public bases can differ from native bases used only for shared storage. */ - tsExtends?: string[]; members?: Member[]; generateSubtreeFacts?: boolean; arena?: boolean; diff --git a/tsc/internal/ast/ast_generated.go b/tsc/internal/ast/ast_generated.go index 556d6485209ba..a8e58c9f01fa9 100644 --- a/tsc/internal/ast/ast_generated.go +++ b/tsc/internal/ast/ast_generated.go @@ -8058,7 +8058,9 @@ func IsJSDocTypedefTag(node *Node) bool { type JSDocSignature struct { JSDocTypeBase DeclarationBase - FunctionLikeBase + TypeParameters *NodeList // Optional + Parameters *NodeList + Type *JSDocReturnTagNode // Optional } func (f *NodeFactory) NewJSDocSignature(typeParameters *NodeList, parameters *NodeList, typeNode *JSDocReturnTagNode) *Node { @@ -12612,9 +12614,8 @@ var nodeLocalsContainerDataDispatch = [kindFlowReduceLabelData + 1]uint8{ KindMappedType: 22, KindFunctionType: 23, KindConstructorType: 24, - KindJSDocSignature: 25, - KindSourceFile: 26, - KindModuleDeclaration: 27, + KindSourceFile: 25, + KindModuleDeclaration: 26, } func (n *Node) LocalsContainerData() *LocalsContainerBase { @@ -12692,12 +12693,9 @@ func (n *Node) LocalsContainerData() *LocalsContainerBase { // SAFETY: This case only matches kinds allocated as a ConstructorTypeNode, which embeds its Node header at offset zero. return (*ConstructorTypeNode)(unsafe.Pointer(n)).LocalsContainerData() case 25: - // SAFETY: This case only matches kinds allocated as a JSDocSignature, which embeds its Node header at offset zero. - return (*JSDocSignature)(unsafe.Pointer(n)).LocalsContainerData() - case 26: // SAFETY: This case only matches kinds allocated as a SourceFile, which embeds its Node header at offset zero. return (*SourceFile)(unsafe.Pointer(n)).LocalsContainerData() - case 27: + case 26: // SAFETY: This case only matches kinds allocated as a ModuleDeclaration, which embeds its Node header at offset zero. return (*ModuleDeclaration)(unsafe.Pointer(n)).LocalsContainerData() default: @@ -12719,7 +12717,6 @@ var nodeFunctionLikeDataDispatch = [kindFlowReduceLabelData + 1]uint8{ KindFunctionExpression: 11, KindFunctionType: 12, KindConstructorType: 13, - KindJSDocSignature: 14, } func (n *Node) FunctionLikeData() *FunctionLikeBase { @@ -12763,9 +12760,6 @@ func (n *Node) FunctionLikeData() *FunctionLikeBase { case 13: // SAFETY: This case only matches kinds allocated as a ConstructorTypeNode, which embeds its Node header at offset zero. return (*ConstructorTypeNode)(unsafe.Pointer(n)).FunctionLikeData() - case 14: - // SAFETY: This case only matches kinds allocated as a JSDocSignature, which embeds its Node header at offset zero. - return (*JSDocSignature)(unsafe.Pointer(n)).FunctionLikeData() default: return nil } diff --git a/tsc/internal/ast/utilities.go b/tsc/internal/ast/utilities.go index f178903372dc2..f65649f4f989b 100644 --- a/tsc/internal/ast/utilities.go +++ b/tsc/internal/ast/utilities.go @@ -553,7 +553,6 @@ func IsFunctionLikeKind(kind Kind) bool { switch kind { case KindMethodSignature, KindCallSignature, - KindJSDocSignature, KindConstructSignature, KindIndexSignature, KindFunctionType, diff --git a/tsc/internal/parser/reparser.go b/tsc/internal/parser/reparser.go index ef420f7e19971..29b84607d3413 100644 --- a/tsc/internal/parser/reparser.go +++ b/tsc/internal/parser/reparser.go @@ -165,7 +165,7 @@ func (p *Parser) reparseJSDocSignature(jsSignature *ast.Node, fun *ast.Node, jsD signature.FunctionLikeData().TypeParameters = p.gatherTypeParameters(jsDoc, false /*typedefOrCallback*/) } parameters := p.nodeSliceArena.NewSlice(0) - for pi, param := range jsSignature.Parameters() { + for pi, param := range jsSignature.AsJSDocSignature().Parameters.Nodes { var parameter *ast.Node if param.Kind == ast.KindJSDocThisTag { thisTag := param.AsJSDocThisTag() @@ -232,8 +232,8 @@ func (p *Parser) reparseJSDocSignature(jsSignature *ast.Node, fun *ast.Node, jsD } signature.FunctionLikeData().Parameters = p.newNodeList(jsSignature.AsJSDocSignature().Parameters.Loc, parameters) - if jsSignature.Type() != nil && jsSignature.Type().TypeExpression() != nil { - signature.FunctionLikeData().Type = p.addDeepCloneReparse(jsSignature.Type().TypeExpression().Type()) + if returnTag := jsSignature.AsJSDocSignature().Type; returnTag != nil && returnTag.TypeExpression() != nil { + signature.FunctionLikeData().Type = p.addDeepCloneReparse(returnTag.TypeExpression().Type()) } loc := jsSignature if tag.Kind == ast.KindJSDocOverloadTag {