Handle missing return type nodes and nested type references missing type 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
This commit is contained in:
Wesley Wigham
2020-06-10 12:42:38 -07:00
committed by GitHub
parent 852e7a0b60
commit 2287dbc7e2
6 changed files with 147 additions and 4 deletions

View File

@@ -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)) {

View File

@@ -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;

View File

@@ -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))

View File

@@ -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

View File

@@ -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])

View File

@@ -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; }