diff --git a/src/compiler/binder.ts b/src/compiler/binder.ts index 204a979d928f8..ec3e81575897f 100644 --- a/src/compiler/binder.ts +++ b/src/compiler/binder.ts @@ -2178,7 +2178,10 @@ namespace ts { case SyntaxKind.JSDocRecordMember: return bindPropertyWorker(node as JSDocRecordMember); case SyntaxKind.JSDocPropertyTag: - return declareSymbolAndAddToSymbolTable(node as JSDocPropertyTag, SymbolFlags.Property, SymbolFlags.PropertyExcludes); + return declareSymbolAndAddToSymbolTable(node as JSDocPropertyTag, + (node as JSDocPropertyTag).typeExpression && (node as JSDocPropertyTag).typeExpression.type.kind === SyntaxKind.JSDocOptionalType ? + SymbolFlags.Property | SymbolFlags.Optional : SymbolFlags.Property, + SymbolFlags.PropertyExcludes); case SyntaxKind.JSDocFunctionType: return bindFunctionOrConstructorType(node); case SyntaxKind.JSDocTypeLiteral: @@ -3593,4 +3596,4 @@ namespace ts { return TransformFlags.NodeExcludes; } } -} +} \ No newline at end of file diff --git a/tests/baselines/reference/checkJsdocTypedefInParamTag1.js b/tests/baselines/reference/checkJsdocTypedefInParamTag1.js new file mode 100644 index 0000000000000..28d6a96b3f916 --- /dev/null +++ b/tests/baselines/reference/checkJsdocTypedefInParamTag1.js @@ -0,0 +1,24 @@ +//// [0.js] +// @ts-check +/** + * @typedef {Object} Opts + * @property {string} x + * @property {string=} y + * + * @param {Opts} opts + */ +function foo(opts) {} + +foo({x: 'abc'}); + +//// [0.js] +// @ts-check +/** + * @typedef {Object} Opts + * @property {string} x + * @property {string=} y + * + * @param {Opts} opts + */ +function foo(opts) { } +foo({ x: 'abc' }); diff --git a/tests/baselines/reference/checkJsdocTypedefInParamTag1.symbols b/tests/baselines/reference/checkJsdocTypedefInParamTag1.symbols new file mode 100644 index 0000000000000..19672d6e52c83 --- /dev/null +++ b/tests/baselines/reference/checkJsdocTypedefInParamTag1.symbols @@ -0,0 +1,17 @@ +=== tests/cases/conformance/jsdoc/0.js === +// @ts-check +/** + * @typedef {Object} Opts + * @property {string} x + * @property {string=} y + * + * @param {Opts} opts + */ +function foo(opts) {} +>foo : Symbol(foo, Decl(0.js, 0, 0)) +>opts : Symbol(opts, Decl(0.js, 8, 13)) + +foo({x: 'abc'}); +>foo : Symbol(foo, Decl(0.js, 0, 0)) +>x : Symbol(x, Decl(0.js, 10, 5)) + diff --git a/tests/baselines/reference/checkJsdocTypedefInParamTag1.types b/tests/baselines/reference/checkJsdocTypedefInParamTag1.types new file mode 100644 index 0000000000000..ff30e8da8a8ae --- /dev/null +++ b/tests/baselines/reference/checkJsdocTypedefInParamTag1.types @@ -0,0 +1,20 @@ +=== tests/cases/conformance/jsdoc/0.js === +// @ts-check +/** + * @typedef {Object} Opts + * @property {string} x + * @property {string=} y + * + * @param {Opts} opts + */ +function foo(opts) {} +>foo : (opts: { x: string; y?: string; }) => void +>opts : { x: string; y?: string; } + +foo({x: 'abc'}); +>foo({x: 'abc'}) : void +>foo : (opts: { x: string; y?: string; }) => void +>{x: 'abc'} : { x: string; } +>x : string +>'abc' : "abc" + diff --git a/tests/cases/conformance/jsdoc/checkJsdocTypedefInParamTag1.ts b/tests/cases/conformance/jsdoc/checkJsdocTypedefInParamTag1.ts new file mode 100644 index 0000000000000..261ce070cf25e --- /dev/null +++ b/tests/cases/conformance/jsdoc/checkJsdocTypedefInParamTag1.ts @@ -0,0 +1,15 @@ +// @allowJS: true +// @suppressOutputPathCheck: true + +// @filename: 0.js +// @ts-check +/** + * @typedef {Object} Opts + * @property {string} x + * @property {string=} y + * + * @param {Opts} opts + */ +function foo(opts) {} + +foo({x: 'abc'}); \ No newline at end of file