diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 87aa1e346265d..299deb8cf84c1 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -5652,7 +5652,7 @@ namespace ts { visitNode(p.type, visitExistingNodeTreeSymbols), /*initializer*/ undefined )), - visitNode(newTypeNode || node.type, visitExistingNodeTreeSymbols) + visitNode(newTypeNode || node.type, visitExistingNodeTreeSymbols) || createKeywordTypeNode(SyntaxKind.AnyKeyword) ); } else { @@ -5667,11 +5667,11 @@ namespace ts { visitNode(p.type, visitExistingNodeTreeSymbols), /*initializer*/ undefined )), - visitNode(node.type, visitExistingNodeTreeSymbols) + visitNode(node.type, visitExistingNodeTreeSymbols) || createKeywordTypeNode(SyntaxKind.AnyKeyword) ); } } - if (isTypeReferenceNode(node) && isInJSDoc(node) && (getIntendedTypeFromJSDocTypeReference(node) || unknownSymbol === resolveTypeReferenceName(getTypeReferenceName(node), SymbolFlags.Type, /*ignoreErrors*/ true))) { + if (isTypeReferenceNode(node) && isInJSDoc(node) && (!existingTypeNodeIsNotReferenceOrIsReferenceWithCompatibleTypeArgumentCount(node, getTypeFromTypeNode(node)) || getIntendedTypeFromJSDocTypeReference(node) || unknownSymbol === resolveTypeReferenceName(getTypeReferenceName(node), SymbolFlags.Type, /*ignoreErrors*/ true))) { return setOriginalNode(typeToTypeNodeHelper(getTypeFromTypeNode(node), context), node); } if (isLiteralImportTypeNode(node)) { diff --git a/tests/baselines/reference/jsDeclarationsMissingTypeParameters.js b/tests/baselines/reference/jsDeclarationsMissingTypeParameters.js new file mode 100644 index 0000000000000..72f6db079f740 --- /dev/null +++ b/tests/baselines/reference/jsDeclarationsMissingTypeParameters.js @@ -0,0 +1,59 @@ +//// [file.js] +/** + * @param {Array=} y desc + */ +function x(y) { } + +// @ts-ignore +/** @param {function (Array)} func Invoked + */ +function y(func) { return; } + +/** + * @return {(Array.<> | null)} list of devices + */ +function z() { return null ;} + +/** + * + * @return {?Promise} A promise + */ +function w() { return null; } + +//// [file.js] +/** + * @param {Array=} y desc + */ +function x(y) { } +// @ts-ignore +/** @param {function (Array)} func Invoked + */ +function y(func) { return; } +/** + * @return {(Array.<> | null)} list of devices + */ +function z() { return null; } +/** + * + * @return {?Promise} A promise + */ +function w() { return null; } + + +//// [file.d.ts] +/** + * @param {Array=} y desc + */ +declare function x(y?: any[] | undefined): void; +/** @param {function (Array)} func Invoked + */ +declare function y(func: (arg0: any[]) => any): void; +/** + * @return {(Array.<> | null)} list of devices + */ +declare function z(): (any[] | null); +/** + * + * @return {?Promise} A promise + */ +declare function w(): Promise | null; diff --git a/tests/baselines/reference/jsDeclarationsMissingTypeParameters.symbols b/tests/baselines/reference/jsDeclarationsMissingTypeParameters.symbols new file mode 100644 index 0000000000000..d1039f3fba6a0 --- /dev/null +++ b/tests/baselines/reference/jsDeclarationsMissingTypeParameters.symbols @@ -0,0 +1,28 @@ +=== tests/cases/conformance/jsdoc/declarations/file.js === +/** + * @param {Array=} y desc + */ +function x(y) { } +>x : Symbol(x, Decl(file.js, 0, 0)) +>y : Symbol(y, Decl(file.js, 3, 11)) + +// @ts-ignore +/** @param {function (Array)} func Invoked + */ +function y(func) { return; } +>y : Symbol(y, Decl(file.js, 3, 17)) +>func : Symbol(func, Decl(file.js, 8, 11)) + +/** + * @return {(Array.<> | null)} list of devices + */ +function z() { return null ;} +>z : Symbol(z, Decl(file.js, 8, 28)) + +/** + * + * @return {?Promise} A promise + */ +function w() { return null; } +>w : Symbol(w, Decl(file.js, 13, 29)) + diff --git a/tests/baselines/reference/jsDeclarationsMissingTypeParameters.types b/tests/baselines/reference/jsDeclarationsMissingTypeParameters.types new file mode 100644 index 0000000000000..cd2fc54197385 --- /dev/null +++ b/tests/baselines/reference/jsDeclarationsMissingTypeParameters.types @@ -0,0 +1,30 @@ +=== tests/cases/conformance/jsdoc/declarations/file.js === +/** + * @param {Array=} y desc + */ +function x(y) { } +>x : (y?: any[] | undefined) => void +>y : any[] + +// @ts-ignore +/** @param {function (Array)} func Invoked + */ +function y(func) { return; } +>y : (func: (arg0: any[]) => any) => void +>func : (arg0: any[]) => any + +/** + * @return {(Array.<> | null)} list of devices + */ +function z() { return null ;} +>z : () => (any[] | null) +>null : null + +/** + * + * @return {?Promise} A promise + */ +function w() { return null; } +>w : () => Promise | null +>null : null + diff --git a/tests/baselines/reference/jsdocParseDotDotDotInJSDocFunction.types b/tests/baselines/reference/jsdocParseDotDotDotInJSDocFunction.types index b015f0f50c3e0..6bc60f6d34432 100644 --- a/tests/baselines/reference/jsdocParseDotDotDotInJSDocFunction.types +++ b/tests/baselines/reference/jsdocParseDotDotDotInJSDocFunction.types @@ -2,7 +2,7 @@ // from bcryptjs /** @param {function(...[*])} callback */ function g(callback) { ->g : (callback: (...args: [any][]) => ) => void +>g : (callback: (...args: [any][]) => any) => void >callback : (...arg0: [any][]) => any callback([1], [2], [3]) diff --git a/tests/cases/conformance/jsdoc/declarations/jsDeclarationsMissingTypeParameters.ts b/tests/cases/conformance/jsdoc/declarations/jsDeclarationsMissingTypeParameters.ts new file mode 100644 index 0000000000000..c924ef7455282 --- /dev/null +++ b/tests/cases/conformance/jsdoc/declarations/jsDeclarationsMissingTypeParameters.ts @@ -0,0 +1,26 @@ +// @allowJs: true +// @checkJs: true +// @target: es5 +// @outDir: ./out +// @declaration: true +// @filename: file.js +/** + * @param {Array=} y desc + */ +function x(y) { } + +// @ts-ignore +/** @param {function (Array)} func Invoked + */ +function y(func) { return; } + +/** + * @return {(Array.<> | null)} list of devices + */ +function z() { return null ;} + +/** + * + * @return {?Promise} A promise + */ +function w() { return null; } \ No newline at end of file