Skip to content

Commit 068256b

Browse files
authored
Merge pull request #16070 from Microsoft/master-15916
[Master] Take into account optional property in parameter
2 parents 1596143 + 23be471 commit 068256b

File tree

5 files changed

+81
-2
lines changed

5 files changed

+81
-2
lines changed

src/compiler/binder.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2178,7 +2178,10 @@ namespace ts {
21782178
case SyntaxKind.JSDocRecordMember:
21792179
return bindPropertyWorker(node as JSDocRecordMember);
21802180
case SyntaxKind.JSDocPropertyTag:
2181-
return declareSymbolAndAddToSymbolTable(node as JSDocPropertyTag, SymbolFlags.Property, SymbolFlags.PropertyExcludes);
2181+
return declareSymbolAndAddToSymbolTable(node as JSDocPropertyTag,
2182+
(node as JSDocPropertyTag).typeExpression && (node as JSDocPropertyTag).typeExpression.type.kind === SyntaxKind.JSDocOptionalType ?
2183+
SymbolFlags.Property | SymbolFlags.Optional : SymbolFlags.Property,
2184+
SymbolFlags.PropertyExcludes);
21822185
case SyntaxKind.JSDocFunctionType:
21832186
return bindFunctionOrConstructorType(<SignatureDeclaration>node);
21842187
case SyntaxKind.JSDocTypeLiteral:
@@ -3593,4 +3596,4 @@ namespace ts {
35933596
return TransformFlags.NodeExcludes;
35943597
}
35953598
}
3596-
}
3599+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
//// [0.js]
2+
// @ts-check
3+
/**
4+
* @typedef {Object} Opts
5+
* @property {string} x
6+
* @property {string=} y
7+
*
8+
* @param {Opts} opts
9+
*/
10+
function foo(opts) {}
11+
12+
foo({x: 'abc'});
13+
14+
//// [0.js]
15+
// @ts-check
16+
/**
17+
* @typedef {Object} Opts
18+
* @property {string} x
19+
* @property {string=} y
20+
*
21+
* @param {Opts} opts
22+
*/
23+
function foo(opts) { }
24+
foo({ x: 'abc' });
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
=== tests/cases/conformance/jsdoc/0.js ===
2+
// @ts-check
3+
/**
4+
* @typedef {Object} Opts
5+
* @property {string} x
6+
* @property {string=} y
7+
*
8+
* @param {Opts} opts
9+
*/
10+
function foo(opts) {}
11+
>foo : Symbol(foo, Decl(0.js, 0, 0))
12+
>opts : Symbol(opts, Decl(0.js, 8, 13))
13+
14+
foo({x: 'abc'});
15+
>foo : Symbol(foo, Decl(0.js, 0, 0))
16+
>x : Symbol(x, Decl(0.js, 10, 5))
17+
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
=== tests/cases/conformance/jsdoc/0.js ===
2+
// @ts-check
3+
/**
4+
* @typedef {Object} Opts
5+
* @property {string} x
6+
* @property {string=} y
7+
*
8+
* @param {Opts} opts
9+
*/
10+
function foo(opts) {}
11+
>foo : (opts: { x: string; y?: string; }) => void
12+
>opts : { x: string; y?: string; }
13+
14+
foo({x: 'abc'});
15+
>foo({x: 'abc'}) : void
16+
>foo : (opts: { x: string; y?: string; }) => void
17+
>{x: 'abc'} : { x: string; }
18+
>x : string
19+
>'abc' : "abc"
20+
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// @allowJS: true
2+
// @suppressOutputPathCheck: true
3+
4+
// @filename: 0.js
5+
// @ts-check
6+
/**
7+
* @typedef {Object} Opts
8+
* @property {string} x
9+
* @property {string=} y
10+
*
11+
* @param {Opts} opts
12+
*/
13+
function foo(opts) {}
14+
15+
foo({x: 'abc'});

0 commit comments

Comments
 (0)