Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle missing return type nodes and nested type references missing type arguments in existing jsdoc node serialization #39011

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/compiler/checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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)) {
Expand Down
59 changes: 59 additions & 0 deletions tests/baselines/reference/jsDeclarationsMissingTypeParameters.js
Original file line number Diff line number Diff line change
@@ -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<any> | null;
Original file line number Diff line number Diff line change
@@ -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))

Original file line number Diff line number Diff line change
@@ -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<any> | null
>null : null

Original file line number Diff line number Diff line change
Expand Up @@ -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])
Expand Down
Original file line number Diff line number Diff line change
@@ -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; }