Skip to content

Commit 90f12d6

Browse files
TypeScript Botweswigham
TypeScript Bot
andauthored
Cherry-pick PR microsoft#38276 into release-3.9 (microsoft#38300)
Component commits: b664c3d Fix jsdoc variadic type nodes not being remapped to equivalent TS in output Co-authored-by: Wesley Wigham <[email protected]>
1 parent 67ca514 commit 90f12d6

6 files changed

+16
-9
lines changed

src/compiler/checker.ts

+11-4
Original file line numberDiff line numberDiff line change
@@ -5566,6 +5566,9 @@ namespace ts {
55665566
if (isJSDocNonNullableType(node)) {
55675567
return visitNode(node.type, visitExistingNodeTreeSymbols);
55685568
}
5569+
if (isJSDocVariadicType(node)) {
5570+
return createArrayTypeNode(visitNode((node as JSDocVariadicType).type, visitExistingNodeTreeSymbols));
5571+
}
55695572
if (isTypeReferenceNode(node) && isIdentifier(node.typeName) && node.typeName.escapedText === "") {
55705573
return setOriginalNode(createKeywordTypeNode(SyntaxKind.AnyKeyword), node);
55715574
}
@@ -5592,8 +5595,8 @@ namespace ts {
55925595
mapDefined(node.parameters, (p, i) => p.name && isIdentifier(p.name) && p.name.escapedText === "new" ? (newTypeNode = p.type, undefined) : createParameter(
55935596
/*decorators*/ undefined,
55945597
/*modifiers*/ undefined,
5595-
p.dotDotDotToken,
5596-
p.name || p.dotDotDotToken ? `args` : `arg${i}`,
5598+
getEffectiveDotDotDotForParameter(p),
5599+
p.name || getEffectiveDotDotDotForParameter(p) ? `args` : `arg${i}`,
55975600
p.questionToken,
55985601
visitNode(p.type, visitExistingNodeTreeSymbols),
55995602
/*initializer*/ undefined
@@ -5607,8 +5610,8 @@ namespace ts {
56075610
map(node.parameters, (p, i) => createParameter(
56085611
/*decorators*/ undefined,
56095612
/*modifiers*/ undefined,
5610-
p.dotDotDotToken,
5611-
p.name || p.dotDotDotToken ? `args` : `arg${i}`,
5613+
getEffectiveDotDotDotForParameter(p),
5614+
p.name || getEffectiveDotDotDotForParameter(p) ? `args` : `arg${i}`,
56125615
p.questionToken,
56135616
visitNode(p.type, visitExistingNodeTreeSymbols),
56145617
/*initializer*/ undefined
@@ -5652,6 +5655,10 @@ namespace ts {
56525655

56535656
return visitEachChild(node, visitExistingNodeTreeSymbols, nullTransformationContext);
56545657

5658+
function getEffectiveDotDotDotForParameter(p: ParameterDeclaration) {
5659+
return p.dotDotDotToken || (p.type && isJSDocVariadicType(p.type) ? createToken(SyntaxKind.DotDotDotToken) : undefined);
5660+
}
5661+
56555662
function rewriteModuleSpecifier(parent: ImportTypeNode, lit: StringLiteral) {
56565663
if (bundled) {
56575664
if (context.tracker && context.tracker.moduleResolverHost) {

tests/baselines/reference/jsFileCompilationRestParamJsDocFunction.types

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
* @returns {*} Returns the result of `func`.
1111
*/
1212
function apply(func, thisArg, ...args) {
13-
>apply : (func: Function, thisArg: any, ...args: ...*) => any
13+
>apply : (func: Function, thisArg: any, ...args: any[]) => any
1414
>func : Function
1515
>thisArg : any
1616
>args : any[]

tests/baselines/reference/jsdocParseDotDotDotInJSDocFunction.types

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// from bcryptjs
33
/** @param {function(...[*])} callback */
44
function g(callback) {
5-
>g : (callback: (arg0: ...[*]) => ) => void
5+
>g : (callback: (...args: [any][]) => ) => void
66
>callback : (...arg0: [any][]) => any
77

88
callback([1], [2], [3])

tests/baselines/reference/jsdocParseStarEquals.types

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
/** @param {...*=} args
33
@return {*=} */
44
function f(...args) {
5-
>f : (...args: ...*=) => any | undefined
5+
>f : (...args: (any | undefined)[]) => any | undefined
66
>args : any[]
77

88
return null

tests/baselines/reference/jsdocPrefixPostfixParsing.types

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
* @param {...number?[]!} k - (number[] | null)[]
1616
*/
1717
function f(x, y, z, a, b, c, e, f, g, h, i, j, k) {
18-
>f : (x: number[], y: number[], z: (number[]), a: (number | null)[], b: number[] | null, c: (number[]) | null, e: ...?number, f: ...?number, g: ...?!number, h: ...!?number, i: ...number[], j: ...?!number[], k: ...!?number[]) => void
18+
>f : (x: number[], y: number[], z: (number[]), a: (number | null)[], b: number[] | null, c: (number[]) | null, e: (number | null)[], f: (number | null)[], g: (number | null)[], h: (number | null)[], i: number[][], j: (number[] | null)[], k: (number | null)[][]) => void
1919
>x : number[]
2020
>y : number[]
2121
>z : number[]

tests/baselines/reference/jsdocRestParameter_es6.types

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
=== /a.js ===
22
/** @param {...number} a */
33
function f(...a) {
4-
>f : (...a: ...number) => void
4+
>f : (...a: number[]) => void
55
>a : number[]
66

77
a; // number[]

0 commit comments

Comments
 (0)