Skip to content

Commit 9df2931

Browse files
author
Kanchalai Tanglertsampan
committed
Add tests and update baselines
1 parent 3062d36 commit 9df2931

7 files changed

+83
-16
lines changed

tests/baselines/reference/checkJsdocTypeTagOnObjectProperty1.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,15 @@ const obj = {
1414
lol,
1515
/** @type {number} */
1616
['b' + 'ar1']: 42,
17+
/** @type {function(number): number} */
18+
arrowFunc: (num) => num + 42
1719
}
1820
obj.foo = 'string'
1921
obj.lol
2022
obj.bar = undefined;
2123
var k = obj.method1(0);
22-
obj.bar1 = "42";
24+
obj.bar1 = "42";
25+
obj.arrowFunc(0);
2326

2427
//// [0.js]
2528
// @ts-check
@@ -38,10 +41,13 @@ var obj = (_a = {
3841
},
3942
/** @type {number} */
4043
_a['b' + 'ar1'] = 42,
44+
/** @type {function(number): number} */
45+
_a.arrowFunc = function (num) { return num + 42; },
4146
_a);
4247
obj.foo = 'string';
4348
obj.lol;
4449
obj.bar = undefined;
4550
var k = obj.method1(0);
4651
obj.bar1 = "42";
52+
obj.arrowFunc(0);
4753
var _a;

tests/baselines/reference/checkJsdocTypeTagOnObjectProperty1.symbols

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,11 @@ const obj = {
3030

3131
/** @type {number} */
3232
['b' + 'ar1']: 42,
33+
/** @type {function(number): number} */
34+
arrowFunc: (num) => num + 42
35+
>arrowFunc : Symbol(arrowFunc, Decl(0.js, 14, 20))
36+
>num : Symbol(num, Decl(0.js, 16, 14))
37+
>num : Symbol(num, Decl(0.js, 16, 14))
3338
}
3439
obj.foo = 'string'
3540
>obj.foo : Symbol(foo, Decl(0.js, 2, 13))
@@ -48,11 +53,16 @@ obj.bar = undefined;
4853
>undefined : Symbol(undefined)
4954

5055
var k = obj.method1(0);
51-
>k : Symbol(k, Decl(0.js, 19, 3))
56+
>k : Symbol(k, Decl(0.js, 21, 3))
5257
>obj.method1 : Symbol(method1, Decl(0.js, 6, 12))
5358
>obj : Symbol(obj, Decl(0.js, 2, 5))
5459
>method1 : Symbol(method1, Decl(0.js, 6, 12))
5560

5661
obj.bar1 = "42";
5762
>obj : Symbol(obj, Decl(0.js, 2, 5))
5863

64+
obj.arrowFunc(0);
65+
>obj.arrowFunc : Symbol(arrowFunc, Decl(0.js, 14, 20))
66+
>obj : Symbol(obj, Decl(0.js, 2, 5))
67+
>arrowFunc : Symbol(arrowFunc, Decl(0.js, 14, 20))
68+

tests/baselines/reference/checkJsdocTypeTagOnObjectProperty1.types

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ var lol = "hello Lol"
55
>"hello Lol" : "hello Lol"
66

77
const obj = {
8-
>obj : { [x: string]: any; foo: string | undefined; bar: string | undefined; method1(arg0: number): number; lol: string; }
9-
>{ /** @type {string|undefined} */ foo: undefined, /** @type {string|undefined} */ bar: "42", /** @type {function(number): number} */ method1(n1) { return n1 + 42; }, /** @type {string} */ lol, /** @type {number} */ ['b' + 'ar1']: 42,} : { [x: string]: any; foo: string | undefined; bar: string | undefined; method1(arg0: number): number; lol: string; }
8+
>obj : { [x: string]: any; foo: string | undefined; bar: string | undefined; method1(arg0: number): number; lol: string; arrowFunc: (arg0: number) => number; }
9+
>{ /** @type {string|undefined} */ foo: undefined, /** @type {string|undefined} */ bar: "42", /** @type {function(number): number} */ method1(n1) { return n1 + 42; }, /** @type {string} */ lol, /** @type {number} */ ['b' + 'ar1']: 42, /** @type {function(number): number} */ arrowFunc: (num) => num + 42} : { [x: string]: any; foo: string | undefined; bar: string | undefined; method1(arg0: number): number; lol: string; arrowFunc: (arg0: number) => number; }
1010

1111
/** @type {string|undefined} */
1212
foo: undefined,
@@ -38,39 +38,55 @@ const obj = {
3838
>'b' + 'ar1' : string
3939
>'b' : "b"
4040
>'ar1' : "ar1"
41+
>42 : 42
42+
43+
/** @type {function(number): number} */
44+
arrowFunc: (num) => num + 42
45+
>arrowFunc : (arg0: number) => number
46+
>(num) => num + 42 : (num: any) => any
47+
>num : any
48+
>num + 42 : any
49+
>num : any
4150
>42 : 42
4251
}
4352
obj.foo = 'string'
4453
>obj.foo = 'string' : "string"
4554
>obj.foo : string | undefined
46-
>obj : { [x: string]: any; foo: string | undefined; bar: string | undefined; method1(arg0: number): number; lol: string; }
55+
>obj : { [x: string]: any; foo: string | undefined; bar: string | undefined; method1(arg0: number): number; lol: string; arrowFunc: (arg0: number) => number; }
4756
>foo : string | undefined
4857
>'string' : "string"
4958

5059
obj.lol
5160
>obj.lol : string
52-
>obj : { [x: string]: any; foo: string | undefined; bar: string | undefined; method1(arg0: number): number; lol: string; }
61+
>obj : { [x: string]: any; foo: string | undefined; bar: string | undefined; method1(arg0: number): number; lol: string; arrowFunc: (arg0: number) => number; }
5362
>lol : string
5463

5564
obj.bar = undefined;
5665
>obj.bar = undefined : undefined
5766
>obj.bar : string | undefined
58-
>obj : { [x: string]: any; foo: string | undefined; bar: string | undefined; method1(arg0: number): number; lol: string; }
67+
>obj : { [x: string]: any; foo: string | undefined; bar: string | undefined; method1(arg0: number): number; lol: string; arrowFunc: (arg0: number) => number; }
5968
>bar : string | undefined
6069
>undefined : undefined
6170

6271
var k = obj.method1(0);
6372
>k : number
6473
>obj.method1(0) : number
6574
>obj.method1 : (arg0: number) => number
66-
>obj : { [x: string]: any; foo: string | undefined; bar: string | undefined; method1(arg0: number): number; lol: string; }
75+
>obj : { [x: string]: any; foo: string | undefined; bar: string | undefined; method1(arg0: number): number; lol: string; arrowFunc: (arg0: number) => number; }
6776
>method1 : (arg0: number) => number
6877
>0 : 0
6978

7079
obj.bar1 = "42";
7180
>obj.bar1 = "42" : "42"
7281
>obj.bar1 : any
73-
>obj : { [x: string]: any; foo: string | undefined; bar: string | undefined; method1(arg0: number): number; lol: string; }
82+
>obj : { [x: string]: any; foo: string | undefined; bar: string | undefined; method1(arg0: number): number; lol: string; arrowFunc: (arg0: number) => number; }
7483
>bar1 : any
7584
>"42" : "42"
7685

86+
obj.arrowFunc(0);
87+
>obj.arrowFunc(0) : number
88+
>obj.arrowFunc : (arg0: number) => number
89+
>obj : { [x: string]: any; foo: string | undefined; bar: string | undefined; method1(arg0: number): number; lol: string; arrowFunc: (arg0: number) => number; }
90+
>arrowFunc : (arg0: number) => number
91+
>0 : 0
92+

tests/baselines/reference/checkJsdocTypeTagOnObjectProperty2.errors.txt

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,15 @@ tests/cases/conformance/jsdoc/0.js(7,3): error TS2322: Type '(n1: any) => string
33
Type 'string' is not assignable to type 'number'.
44
tests/cases/conformance/jsdoc/0.js(11,3): error TS2322: Type '(n1: any) => string' is not assignable to type '(arg0: number) => number'.
55
Type 'string' is not assignable to type 'number'.
6-
tests/cases/conformance/jsdoc/0.js(13,3): error TS2322: Type 'undefined' is not assignable to type 'string'.
7-
tests/cases/conformance/jsdoc/0.js(17,5): error TS2322: Type 'number' is not assignable to type 'string'.
6+
tests/cases/conformance/jsdoc/0.js(13,3): error TS2322: Type '(num?: string) => string' is not assignable to type '(arg0: number) => number'.
7+
Types of parameters 'num' and 'arg0' are incompatible.
8+
Type 'number' is not assignable to type 'string | undefined'.
9+
tests/cases/conformance/jsdoc/0.js(15,3): error TS2322: Type 'undefined' is not assignable to type 'string'.
10+
tests/cases/conformance/jsdoc/0.js(19,5): error TS2322: Type 'number' is not assignable to type 'string'.
11+
tests/cases/conformance/jsdoc/0.js(22,22): error TS2345: Argument of type '"0"' is not assignable to parameter of type 'number'.
812

913

10-
==== tests/cases/conformance/jsdoc/0.js (5 errors) ====
14+
==== tests/cases/conformance/jsdoc/0.js (7 errors) ====
1115
// @ts-check
1216
var lol;
1317
const obj = {
@@ -27,6 +31,12 @@ tests/cases/conformance/jsdoc/0.js(17,5): error TS2322: Type 'number' is not ass
2731
~~~~~~~~~~~~~~~~~~~~~~
2832
!!! error TS2322: Type '(n1: any) => string' is not assignable to type '(arg0: number) => number'.
2933
!!! error TS2322: Type 'string' is not assignable to type 'number'.
34+
/** @type {function(number): number} */
35+
arrowFunc: (num="0") => num + 42,
36+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
37+
!!! error TS2322: Type '(num?: string) => string' is not assignable to type '(arg0: number) => number'.
38+
!!! error TS2322: Types of parameters 'num' and 'arg0' are incompatible.
39+
!!! error TS2322: Type 'number' is not assignable to type 'string | undefined'.
3040
/** @type {string} */
3141
lol
3242
~~~
@@ -36,4 +46,9 @@ tests/cases/conformance/jsdoc/0.js(17,5): error TS2322: Type 'number' is not ass
3646
/** @type {string} */
3747
var s = obj.method1(0);
3848
~
39-
!!! error TS2322: Type 'number' is not assignable to type 'string'.
49+
!!! error TS2322: Type 'number' is not assignable to type 'string'.
50+
51+
/** @type {string} */
52+
var s1 = obj.method2("0");
53+
~~~
54+
!!! error TS2345: Argument of type '"0"' is not assignable to parameter of type 'number'.

tests/baselines/reference/checkJsdocTypeTagOnObjectProperty2.js

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,17 @@ const obj = {
1010
},
1111
/** @type {function(number): number} */
1212
method2: (n1) => "lol",
13+
/** @type {function(number): number} */
14+
arrowFunc: (num="0") => num + 42,
1315
/** @type {string} */
1416
lol
1517
}
1618
lol = "string"
1719
/** @type {string} */
18-
var s = obj.method1(0);
20+
var s = obj.method1(0);
21+
22+
/** @type {string} */
23+
var s1 = obj.method2("0");
1924

2025
//// [0.js]
2126
// @ts-check
@@ -29,9 +34,16 @@ var obj = {
2934
},
3035
/** @type {function(number): number} */
3136
method2: function (n1) { return "lol"; },
37+
/** @type {function(number): number} */
38+
arrowFunc: function (num) {
39+
if (num === void 0) { num = "0"; }
40+
return num + 42;
41+
},
3242
/** @type {string} */
3343
lol: lol
3444
};
3545
lol = "string";
3646
/** @type {string} */
3747
var s = obj.method1(0);
48+
/** @type {string} */
49+
var s1 = obj.method2("0");

tests/cases/conformance/jsdoc/checkJsdocTypeTagOnObjectProperty1.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,12 @@ const obj = {
1818
lol,
1919
/** @type {number} */
2020
['b' + 'ar1']: 42,
21+
/** @type {function(number): number} */
22+
arrowFunc: (num) => num + 42
2123
}
2224
obj.foo = 'string'
2325
obj.lol
2426
obj.bar = undefined;
2527
var k = obj.method1(0);
26-
obj.bar1 = "42";
28+
obj.bar1 = "42";
29+
obj.arrowFunc(0);

tests/cases/conformance/jsdoc/checkJsdocTypeTagOnObjectProperty2.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,14 @@ const obj = {
1414
},
1515
/** @type {function(number): number} */
1616
method2: (n1) => "lol",
17+
/** @type {function(number): number} */
18+
arrowFunc: (num="0") => num + 42,
1719
/** @type {string} */
1820
lol
1921
}
2022
lol = "string"
2123
/** @type {string} */
22-
var s = obj.method1(0);
24+
var s = obj.method1(0);
25+
26+
/** @type {string} */
27+
var s1 = obj.method2("0");

0 commit comments

Comments
 (0)