From 5cbef8ea47a969ac62e1400364d9269928f9588c Mon Sep 17 00:00:00 2001 From: Oleksandr Tarasiuk Date: Sat, 15 Nov 2025 02:54:46 +0200 Subject: [PATCH] fix(2047): set default any return type for callback tags without a return tag --- internal/parser/reparser.go | 2 +- .../jsFileAlternativeUseOfOverloadTag.js | 64 +----------------- .../jsFileAlternativeUseOfOverloadTag.js.diff | 66 +------------------ .../jsDeclarationsFunctionPrototypeStatic.js | 2 +- ...eclarationsFunctionPrototypeStatic.js.diff | 2 +- ...tionsParameterTagReusesInputNodeInEmit1.js | 2 +- ...ParameterTagReusesInputNodeInEmit1.js.diff | 2 +- .../conformance/templateInsideCallback.js | 2 +- .../templateInsideCallback.js.diff | 2 +- 9 files changed, 10 insertions(+), 134 deletions(-) diff --git a/internal/parser/reparser.go b/internal/parser/reparser.go index 9d3637e303..892ab56b88 100644 --- a/internal/parser/reparser.go +++ b/internal/parser/reparser.go @@ -132,7 +132,7 @@ func (p *Parser) reparseJSDocSignature(jsSignature *ast.Node, fun *ast.Node, jsD case ast.KindConstructor: signature = p.factory.NewConstructorDeclaration(clonedModifiers, nil, nil, nil, nil, nil) case ast.KindJSDocCallbackTag: - signature = p.factory.NewFunctionTypeNode(nil, nil, nil) + signature = p.factory.NewFunctionTypeNode(nil, nil, p.factory.NewKeywordTypeNode(ast.KindAnyKeyword)) default: panic("Unexpected kind " + fun.Kind.String()) } diff --git a/testdata/baselines/reference/submodule/compiler/jsFileAlternativeUseOfOverloadTag.js b/testdata/baselines/reference/submodule/compiler/jsFileAlternativeUseOfOverloadTag.js index 885131f809..ebe7145997 100644 --- a/testdata/baselines/reference/submodule/compiler/jsFileAlternativeUseOfOverloadTag.js +++ b/testdata/baselines/reference/submodule/compiler/jsFileAlternativeUseOfOverloadTag.js @@ -139,7 +139,7 @@ declare const example2: { constructor: () => void; }; declare function evaluate(): any; -type callback = (error: any, result: any) ; +type callback = (error: any, result: any) => any; declare const example3: { /** * @overload evaluate(options = {}, [callback]) @@ -156,65 +156,3 @@ declare const example3: { */ evaluate: (options: any, callback: any) => void; }; - - -//// [DtsFileErrors] - - -dist/jsFileAlternativeUseOfOverloadTag.d.ts(34,43): error TS1005: '=>' expected. - - -==== dist/jsFileAlternativeUseOfOverloadTag.d.ts (1 errors) ==== - declare function Example1(value: any): any; - declare const example1: { - /** - * @overload Example1(value) - * Creates Example1 - * @param value [String] - */ - constructor: (value: any, options: any) => void; - }; - declare function Example2(value: any, secretAccessKey: any, sessionToken: any): any; - declare function Example2(): any; - declare const example2: { - /** - * Example 2 - * - * @overload Example2(value) - * Creates Example2 - * @param value [String] - * @param secretAccessKey [String] - * @param sessionToken [String] - * @example Creates with string value - * const example = new Example(''); - * @overload Example2(options) - * Creates Example2 - * @option options value [String] - * @example Creates with options object - * const example = new Example2({ - * value: '', - * }); - */ - constructor: () => void; - }; - declare function evaluate(): any; - type callback = (error: any, result: any) ; - ~ -!!! error TS1005: '=>' expected. - declare const example3: { - /** - * @overload evaluate(options = {}, [callback]) - * Evaluate something - * @note Something interesting - * @param options [map] - * @return [string] returns evaluation result - * @return [null] returns nothing if callback provided - * @callback callback function (error, result) - * If callback is provided it will be called with evaluation result - * @param error [Error] - * @param result [String] - * @see callback - */ - evaluate: (options: any, callback: any) => void; - }; - \ No newline at end of file diff --git a/testdata/baselines/reference/submodule/compiler/jsFileAlternativeUseOfOverloadTag.js.diff b/testdata/baselines/reference/submodule/compiler/jsFileAlternativeUseOfOverloadTag.js.diff index d133646bf0..f2d21bc5a2 100644 --- a/testdata/baselines/reference/submodule/compiler/jsFileAlternativeUseOfOverloadTag.js.diff +++ b/testdata/baselines/reference/submodule/compiler/jsFileAlternativeUseOfOverloadTag.js.diff @@ -82,7 +82,7 @@ + constructor: () => void; +}; +declare function evaluate(): any; -+type callback = (error: any, result: any) ; ++type callback = (error: any, result: any) => any; +declare const example3: { /** * @overload evaluate(options = {}, [callback]) @@ -99,66 +99,4 @@ - */ -type callback = (error: any, result: any) => any; + evaluate: (options: any, callback: any) => void; -+}; -+ -+ -+//// [DtsFileErrors] -+ -+ -+dist/jsFileAlternativeUseOfOverloadTag.d.ts(34,43): error TS1005: '=>' expected. -+ -+ -+==== dist/jsFileAlternativeUseOfOverloadTag.d.ts (1 errors) ==== -+ declare function Example1(value: any): any; -+ declare const example1: { -+ /** -+ * @overload Example1(value) -+ * Creates Example1 -+ * @param value [String] -+ */ -+ constructor: (value: any, options: any) => void; -+ }; -+ declare function Example2(value: any, secretAccessKey: any, sessionToken: any): any; -+ declare function Example2(): any; -+ declare const example2: { -+ /** -+ * Example 2 -+ * -+ * @overload Example2(value) -+ * Creates Example2 -+ * @param value [String] -+ * @param secretAccessKey [String] -+ * @param sessionToken [String] -+ * @example Creates with string value -+ * const example = new Example(''); -+ * @overload Example2(options) -+ * Creates Example2 -+ * @option options value [String] -+ * @example Creates with options object -+ * const example = new Example2({ -+ * value: '', -+ * }); -+ */ -+ constructor: () => void; -+ }; -+ declare function evaluate(): any; -+ type callback = (error: any, result: any) ; -+ ~ -+!!! error TS1005: '=>' expected. -+ declare const example3: { -+ /** -+ * @overload evaluate(options = {}, [callback]) -+ * Evaluate something -+ * @note Something interesting -+ * @param options [map] -+ * @return [string] returns evaluation result -+ * @return [null] returns nothing if callback provided -+ * @callback callback function (error, result) -+ * If callback is provided it will be called with evaluation result -+ * @param error [Error] -+ * @param result [String] -+ * @see callback -+ */ -+ evaluate: (options: any, callback: any) => void; -+ }; -+ \ No newline at end of file ++}; \ No newline at end of file diff --git a/testdata/baselines/reference/submodule/conformance/jsDeclarationsFunctionPrototypeStatic.js b/testdata/baselines/reference/submodule/conformance/jsDeclarationsFunctionPrototypeStatic.js index 7a23260882..85050d43ba 100644 --- a/testdata/baselines/reference/submodule/conformance/jsDeclarationsFunctionPrototypeStatic.js +++ b/testdata/baselines/reference/submodule/conformance/jsDeclarationsFunctionPrototypeStatic.js @@ -38,7 +38,7 @@ declare namespace MyClass { declare namespace MyClass { var staticProperty: number; } -export type DoneCB = (failures: number) ; +export type DoneCB = (failures: number) => any; /** * Callback to be invoked when test execution is complete. * diff --git a/testdata/baselines/reference/submodule/conformance/jsDeclarationsFunctionPrototypeStatic.js.diff b/testdata/baselines/reference/submodule/conformance/jsDeclarationsFunctionPrototypeStatic.js.diff index 5c6c9bb910..3a136c55f4 100644 --- a/testdata/baselines/reference/submodule/conformance/jsDeclarationsFunctionPrototypeStatic.js.diff +++ b/testdata/baselines/reference/submodule/conformance/jsDeclarationsFunctionPrototypeStatic.js.diff @@ -18,7 +18,7 @@ +declare namespace MyClass { + var staticProperty: number; +} -+export type DoneCB = (failures: number) ; ++export type DoneCB = (failures: number) => any; /** * Callback to be invoked when test execution is complete. - */ diff --git a/testdata/baselines/reference/submodule/conformance/jsDeclarationsParameterTagReusesInputNodeInEmit1.js b/testdata/baselines/reference/submodule/conformance/jsDeclarationsParameterTagReusesInputNodeInEmit1.js index bd3ba2627c..b3890fb6bb 100644 --- a/testdata/baselines/reference/submodule/conformance/jsDeclarationsParameterTagReusesInputNodeInEmit1.js +++ b/testdata/baselines/reference/submodule/conformance/jsDeclarationsParameterTagReusesInputNodeInEmit1.js @@ -70,7 +70,7 @@ declare namespace BaseFactory { export = BaseFactory; //// [file.d.ts] type BaseFactory = import('./base'); -type BaseFactoryFactory = (factory: import('./base')) ; +type BaseFactoryFactory = (factory: import('./base')) => any; /** @typedef {import('./base')} BaseFactory */ /** * @callback BaseFactoryFactory diff --git a/testdata/baselines/reference/submodule/conformance/jsDeclarationsParameterTagReusesInputNodeInEmit1.js.diff b/testdata/baselines/reference/submodule/conformance/jsDeclarationsParameterTagReusesInputNodeInEmit1.js.diff index d941bf0e81..e0eafe816f 100644 --- a/testdata/baselines/reference/submodule/conformance/jsDeclarationsParameterTagReusesInputNodeInEmit1.js.diff +++ b/testdata/baselines/reference/submodule/conformance/jsDeclarationsParameterTagReusesInputNodeInEmit1.js.diff @@ -25,7 +25,7 @@ - }; -}; +type BaseFactory = import('./base'); -+type BaseFactoryFactory = (factory: import('./base')) ; ++type BaseFactoryFactory = (factory: import('./base')) => any; /** @typedef {import('./base')} BaseFactory */ /** * @callback BaseFactoryFactory diff --git a/testdata/baselines/reference/submodule/conformance/templateInsideCallback.js b/testdata/baselines/reference/submodule/conformance/templateInsideCallback.js index 4f99ceb207..a1f81c866e 100644 --- a/testdata/baselines/reference/submodule/conformance/templateInsideCallback.js +++ b/testdata/baselines/reference/submodule/conformance/templateInsideCallback.js @@ -113,7 +113,7 @@ function flatMap(array, iterable = identity) { //// [templateInsideCallback.d.ts] -type Call = () ; +type Call = () => any; /** * @typedef Oops * @template T diff --git a/testdata/baselines/reference/submodule/conformance/templateInsideCallback.js.diff b/testdata/baselines/reference/submodule/conformance/templateInsideCallback.js.diff index 2abe09db9b..309d6bf33d 100644 --- a/testdata/baselines/reference/submodule/conformance/templateInsideCallback.js.diff +++ b/testdata/baselines/reference/submodule/conformance/templateInsideCallback.js.diff @@ -28,7 +28,7 @@ - * @returns {T[]} - */ -declare function flatMap(): any; -+type Call = () ; ++type Call = () => any; /** * @typedef Oops * @template T