Skip to content

Commit

Permalink
Handle missing return type nodes and nested type references missing t…
Browse files Browse the repository at this point in the history
…ype arguments in existing jsdoc node serialization (#39011)

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

* Accept updated baselines
  • Loading branch information
weswigham authored Jun 10, 2020
1 parent 852e7a0 commit 2287dbc
Show file tree
Hide file tree
Showing 6 changed files with 147 additions and 4 deletions.
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; }

0 comments on commit 2287dbc

Please sign in to comment.