mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-05-30 01:04:49 -05:00
fix(42099): fix JSDoc optional properties declaration emit (#42116)
This commit is contained in:
@@ -5931,7 +5931,7 @@ namespace ts {
|
||||
return factory.createPropertySignature(
|
||||
/*modifiers*/ undefined,
|
||||
name,
|
||||
t.typeExpression && isJSDocOptionalType(t.typeExpression.type) ? factory.createToken(SyntaxKind.QuestionToken) : undefined,
|
||||
t.isBracketed || t.typeExpression && isJSDocOptionalType(t.typeExpression.type) ? factory.createToken(SyntaxKind.QuestionToken) : undefined,
|
||||
overrideTypeNode || (t.typeExpression && visitNode(t.typeExpression.type, visitExistingNodeTreeSymbols)) || factory.createKeywordTypeNode(SyntaxKind.AnyKeyword)
|
||||
);
|
||||
}));
|
||||
|
||||
@@ -0,0 +1,48 @@
|
||||
//// [foo.js]
|
||||
/**
|
||||
* foo
|
||||
*
|
||||
* @public
|
||||
* @param {object} opts
|
||||
* @param {number} opts.a
|
||||
* @param {number} [opts.b]
|
||||
* @param {number} [opts.c]
|
||||
* @returns {number}
|
||||
*/
|
||||
function foo({ a, b, c }) {
|
||||
return a + b + c;
|
||||
}
|
||||
|
||||
|
||||
//// [foo.js]
|
||||
/**
|
||||
* foo
|
||||
*
|
||||
* @public
|
||||
* @param {object} opts
|
||||
* @param {number} opts.a
|
||||
* @param {number} [opts.b]
|
||||
* @param {number} [opts.c]
|
||||
* @returns {number}
|
||||
*/
|
||||
function foo({ a, b, c }) {
|
||||
return a + b + c;
|
||||
}
|
||||
|
||||
|
||||
//// [foo.d.ts]
|
||||
/**
|
||||
* foo
|
||||
*
|
||||
* @public
|
||||
* @param {object} opts
|
||||
* @param {number} opts.a
|
||||
* @param {number} [opts.b]
|
||||
* @param {number} [opts.c]
|
||||
* @returns {number}
|
||||
*/
|
||||
declare function foo({ a, b, c }: {
|
||||
a: number;
|
||||
b?: number;
|
||||
c?: number;
|
||||
}): number;
|
||||
@@ -0,0 +1,23 @@
|
||||
=== tests/cases/conformance/jsdoc/declarations/foo.js ===
|
||||
/**
|
||||
* foo
|
||||
*
|
||||
* @public
|
||||
* @param {object} opts
|
||||
* @param {number} opts.a
|
||||
* @param {number} [opts.b]
|
||||
* @param {number} [opts.c]
|
||||
* @returns {number}
|
||||
*/
|
||||
function foo({ a, b, c }) {
|
||||
>foo : Symbol(foo, Decl(foo.js, 0, 0))
|
||||
>a : Symbol(a, Decl(foo.js, 10, 14))
|
||||
>b : Symbol(b, Decl(foo.js, 10, 17))
|
||||
>c : Symbol(c, Decl(foo.js, 10, 20))
|
||||
|
||||
return a + b + c;
|
||||
>a : Symbol(a, Decl(foo.js, 10, 14))
|
||||
>b : Symbol(b, Decl(foo.js, 10, 17))
|
||||
>c : Symbol(c, Decl(foo.js, 10, 20))
|
||||
}
|
||||
|
||||
@@ -0,0 +1,25 @@
|
||||
=== tests/cases/conformance/jsdoc/declarations/foo.js ===
|
||||
/**
|
||||
* foo
|
||||
*
|
||||
* @public
|
||||
* @param {object} opts
|
||||
* @param {number} opts.a
|
||||
* @param {number} [opts.b]
|
||||
* @param {number} [opts.c]
|
||||
* @returns {number}
|
||||
*/
|
||||
function foo({ a, b, c }) {
|
||||
>foo : ({ a, b, c }: { a: number; b?: number; c?: number;}) => number
|
||||
>a : number
|
||||
>b : number
|
||||
>c : number
|
||||
|
||||
return a + b + c;
|
||||
>a + b + c : number
|
||||
>a + b : number
|
||||
>a : number
|
||||
>b : number
|
||||
>c : number
|
||||
}
|
||||
|
||||
@@ -0,0 +1,49 @@
|
||||
//// [foo.js]
|
||||
/**
|
||||
* foo
|
||||
*
|
||||
* @public
|
||||
* @param {object} opts
|
||||
* @param {number} opts.a
|
||||
* @param {number} [opts.b]
|
||||
* @param {number} [opts.c]
|
||||
* @returns {number}
|
||||
*/
|
||||
function foo({ a, b, c }) {
|
||||
return a + (b ?? 0) + (c ?? 0);
|
||||
}
|
||||
|
||||
|
||||
//// [foo.js]
|
||||
"use strict";
|
||||
/**
|
||||
* foo
|
||||
*
|
||||
* @public
|
||||
* @param {object} opts
|
||||
* @param {number} opts.a
|
||||
* @param {number} [opts.b]
|
||||
* @param {number} [opts.c]
|
||||
* @returns {number}
|
||||
*/
|
||||
function foo({ a, b, c }) {
|
||||
return a + (b ?? 0) + (c ?? 0);
|
||||
}
|
||||
|
||||
|
||||
//// [foo.d.ts]
|
||||
/**
|
||||
* foo
|
||||
*
|
||||
* @public
|
||||
* @param {object} opts
|
||||
* @param {number} opts.a
|
||||
* @param {number} [opts.b]
|
||||
* @param {number} [opts.c]
|
||||
* @returns {number}
|
||||
*/
|
||||
declare function foo({ a, b, c }: {
|
||||
a: number;
|
||||
b?: number | undefined;
|
||||
c?: number | undefined;
|
||||
}): number;
|
||||
@@ -0,0 +1,23 @@
|
||||
=== tests/cases/conformance/jsdoc/declarations/foo.js ===
|
||||
/**
|
||||
* foo
|
||||
*
|
||||
* @public
|
||||
* @param {object} opts
|
||||
* @param {number} opts.a
|
||||
* @param {number} [opts.b]
|
||||
* @param {number} [opts.c]
|
||||
* @returns {number}
|
||||
*/
|
||||
function foo({ a, b, c }) {
|
||||
>foo : Symbol(foo, Decl(foo.js, 0, 0))
|
||||
>a : Symbol(a, Decl(foo.js, 10, 14))
|
||||
>b : Symbol(b, Decl(foo.js, 10, 17))
|
||||
>c : Symbol(c, Decl(foo.js, 10, 20))
|
||||
|
||||
return a + (b ?? 0) + (c ?? 0);
|
||||
>a : Symbol(a, Decl(foo.js, 10, 14))
|
||||
>b : Symbol(b, Decl(foo.js, 10, 17))
|
||||
>c : Symbol(c, Decl(foo.js, 10, 20))
|
||||
}
|
||||
|
||||
@@ -0,0 +1,31 @@
|
||||
=== tests/cases/conformance/jsdoc/declarations/foo.js ===
|
||||
/**
|
||||
* foo
|
||||
*
|
||||
* @public
|
||||
* @param {object} opts
|
||||
* @param {number} opts.a
|
||||
* @param {number} [opts.b]
|
||||
* @param {number} [opts.c]
|
||||
* @returns {number}
|
||||
*/
|
||||
function foo({ a, b, c }) {
|
||||
>foo : ({ a, b, c }: { a: number; b?: number | undefined; c?: number | undefined;}) => number
|
||||
>a : number
|
||||
>b : number | undefined
|
||||
>c : number | undefined
|
||||
|
||||
return a + (b ?? 0) + (c ?? 0);
|
||||
>a + (b ?? 0) + (c ?? 0) : number
|
||||
>a + (b ?? 0) : number
|
||||
>a : number
|
||||
>(b ?? 0) : number
|
||||
>b ?? 0 : number
|
||||
>b : number | undefined
|
||||
>0 : 0
|
||||
>(c ?? 0) : number
|
||||
>c ?? 0 : number
|
||||
>c : number | undefined
|
||||
>0 : 0
|
||||
}
|
||||
|
||||
@@ -23,7 +23,7 @@ normal(12);
|
||||
* @param {string} [opts1.w="hi"] doc5
|
||||
*/
|
||||
function foo1(opts1) {
|
||||
>foo1 : (opts1: { x: string; y?: string | undefined; z: string | undefined; w: string | undefined;}) => void
|
||||
>foo1 : (opts1: { x: string; y?: string | undefined; z?: string | undefined; w?: string | undefined;}) => void
|
||||
>opts1 : { x: string; y?: string | undefined; z?: string | undefined; w?: string | undefined; }
|
||||
|
||||
opts1.x;
|
||||
@@ -92,7 +92,7 @@ foo3({x: 'abc'});
|
||||
* @param {string} [opts4[].w="hi"]
|
||||
*/
|
||||
function foo4(opts4) {
|
||||
>foo4 : (opts4: { x: string; y?: string | undefined; z: string; w: string;}) => void
|
||||
>foo4 : (opts4: { x: string; y?: string | undefined; z?: string; w?: string;}) => void
|
||||
>opts4 : { x: string; y?: string | undefined; z?: string | undefined; w?: string | undefined; }[]
|
||||
|
||||
opts4[0].x;
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
// @allowJs: true
|
||||
// @checkJs: true
|
||||
// @target: esnext
|
||||
// @outDir: ./out
|
||||
// @declaration: true
|
||||
// @filename: foo.js
|
||||
/**
|
||||
* foo
|
||||
*
|
||||
* @public
|
||||
* @param {object} opts
|
||||
* @param {number} opts.a
|
||||
* @param {number} [opts.b]
|
||||
* @param {number} [opts.c]
|
||||
* @returns {number}
|
||||
*/
|
||||
function foo({ a, b, c }) {
|
||||
return a + b + c;
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
// @allowJs: true
|
||||
// @checkJs: true
|
||||
// @strict: true
|
||||
// @target: esnext
|
||||
// @outDir: ./out
|
||||
// @declaration: true
|
||||
// @filename: foo.js
|
||||
/**
|
||||
* foo
|
||||
*
|
||||
* @public
|
||||
* @param {object} opts
|
||||
* @param {number} opts.a
|
||||
* @param {number} [opts.b]
|
||||
* @param {number} [opts.c]
|
||||
* @returns {number}
|
||||
*/
|
||||
function foo({ a, b, c }) {
|
||||
return a + (b ?? 0) + (c ?? 0);
|
||||
}
|
||||
Reference in New Issue
Block a user