Skip to content

Commit e6b1c61

Browse files
committed
add tests for TypeScript 4.3
1 parent 2cc2d11 commit e6b1c61

File tree

6 files changed

+163
-1
lines changed

6 files changed

+163
-1
lines changed
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
| Foo | boolean |
2+
| typeof Foo in global scope | string |
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import javascript
2+
3+
query Type stringIndexType(Type t) { result = t.getStringIndexType() }
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
// static index signature
2+
class Foo {
3+
static hello = "world";
4+
static [n: string]: string;
5+
[n: string]: boolean;
6+
}
7+
Foo["whatever"] = "foo";
8+
new Foo()["something"] = true;

javascript/ql/test/library-tests/TypeScript/Types/tests.expected

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,54 @@ getExprType
127127
| tst.ts:69:24:69:45 | {yetAno ... : true} | MyUnion2 |
128128
| tst.ts:69:25:69:38 | yetAnotherType | true |
129129
| tst.ts:69:41:69:44 | true | true |
130+
| tst.ts:71:8:71:11 | TS43 | typeof TS43 in library-tests/TypeScript/Types/tst.ts |
131+
| tst.ts:74:5:74:22 | get size(): number | number |
132+
| tst.ts:74:9:74:12 | size | number |
133+
| tst.ts:75:5:75:47 | set siz ... olean); | number |
134+
| tst.ts:75:9:75:12 | size | number |
135+
| tst.ts:75:14:75:18 | value | string \| number \| boolean |
136+
| tst.ts:78:16:78:20 | Thing | Thing |
137+
| tst.ts:79:13:79:13 | 0 | 0 |
138+
| tst.ts:81:5:83:5 | get siz ... ;\\n } | number |
139+
| tst.ts:81:9:81:12 | size | number |
140+
| tst.ts:82:14:82:23 | this.#size | number |
141+
| tst.ts:85:5:87:5 | set siz ... ;\\n } | number |
142+
| tst.ts:85:9:85:12 | size | number |
143+
| tst.ts:85:14:85:18 | value | string \| number \| boolean |
144+
| tst.ts:86:7:86:16 | this.#size | number |
145+
| tst.ts:86:7:86:32 | this.#s ... (value) | number |
146+
| tst.ts:86:20:86:25 | Number | NumberConstructor |
147+
| tst.ts:86:20:86:32 | Number(value) | number |
148+
| tst.ts:86:27:86:31 | value | string \| number \| boolean |
149+
| tst.ts:91:9:91:13 | Super | Super |
150+
| tst.ts:92:5:92:10 | random | () => number |
151+
| tst.ts:92:5:94:5 | random( ... ;\\n } | () => number |
152+
| tst.ts:93:14:93:14 | 4 | 4 |
153+
| tst.ts:97:9:97:11 | Sub | Sub |
154+
| tst.ts:97:21:97:25 | Super | Super |
155+
| tst.ts:98:5:100:5 | overrid ... ;\\n } | () => number |
156+
| tst.ts:98:14:98:19 | random | () => number |
157+
| tst.ts:99:14:99:25 | super.random | () => number |
158+
| tst.ts:99:14:99:27 | super.random() | number |
159+
| tst.ts:99:14:99:32 | super.random() * 10 | number |
160+
| tst.ts:99:20:99:25 | random | () => number |
161+
| tst.ts:99:31:99:32 | 10 | 10 |
162+
| tst.ts:104:16:104:16 | s | string |
163+
| tst.ts:106:13:106:18 | hello | any |
164+
| tst.ts:106:21:106:21 | s | string |
165+
| tst.ts:110:15:110:16 | s2 | "1-2-3" |
166+
| tst.ts:112:3:112:9 | s1 = s2 | "1-2-3" |
167+
| tst.ts:112:8:112:9 | s2 | "1-2-3" |
168+
| tst.ts:116:9:116:11 | Foo | Foo |
169+
| tst.ts:117:5:119:5 | #someMe ... ;\\n } | () => number |
170+
| tst.ts:118:14:118:15 | 42 | 42 |
171+
| tst.ts:121:5:123:5 | get #so ... ;\\n } | number |
172+
| tst.ts:122:14:122:16 | 100 | 100 |
173+
| tst.ts:125:5:125:16 | publicMethod | () => number |
174+
| tst.ts:125:5:128:5 | publicM ... ;\\n } | () => number |
175+
| tst.ts:126:7:126:22 | this.#someMethod | () => number |
176+
| tst.ts:126:7:126:24 | this.#someMethod() | number |
177+
| tst.ts:127:14:127:28 | this.#someValue | number |
130178
| type_alias.ts:3:5:3:5 | b | boolean |
131179
| type_alias.ts:7:5:7:5 | c | ValueOrArray<number> |
132180
| type_alias.ts:14:9:14:32 | [proper ... ]: Json | any |
@@ -180,6 +228,11 @@ getTypeDefinitionType
180228
| tst.ts:58:1:60:1 | interfa ... mber;\\n} | HasArea |
181229
| tst.ts:65:1:65:54 | type My ... true}; | MyUnion |
182230
| tst.ts:68:1:68:49 | type My ... true}; | MyUnion2 |
231+
| tst.ts:73:3:76:3 | interfa ... n);\\n } | ThingI |
232+
| tst.ts:78:10:88:3 | class T ... }\\n } | Thing |
233+
| tst.ts:91:3:95:3 | class S ... }\\n } | Super |
234+
| tst.ts:97:3:101:3 | class S ... }\\n } | Sub |
235+
| tst.ts:116:3:129:3 | class F ... }\\n } | Foo |
183236
| type_alias.ts:1:1:1:17 | type B = boolean; | boolean |
184237
| type_alias.ts:5:1:5:50 | type Va ... ay<T>>; | ValueOrArray<T> |
185238
| type_alias.ts:9:1:15:13 | type Js ... Json[]; | Json |
@@ -288,6 +341,34 @@ getTypeExprType
288341
| tst.ts:68:27:68:48 | {yetAno ... : true} | { yetAnotherType: true; } |
289342
| tst.ts:68:44:68:47 | true | true |
290343
| tst.ts:69:13:69:20 | MyUnion2 | MyUnion2 |
344+
| tst.ts:73:13:73:18 | ThingI | ThingI |
345+
| tst.ts:74:17:74:22 | number | number |
346+
| tst.ts:75:21:75:26 | number | number |
347+
| tst.ts:75:21:75:45 | number ... boolean | string \| number \| boolean |
348+
| tst.ts:75:30:75:35 | string | string |
349+
| tst.ts:75:39:75:45 | boolean | boolean |
350+
| tst.ts:78:33:78:38 | ThingI | ThingI |
351+
| tst.ts:81:17:81:22 | number | number |
352+
| tst.ts:85:21:85:26 | string | string |
353+
| tst.ts:85:21:85:45 | string ... boolean | string \| number \| boolean |
354+
| tst.ts:85:30:85:35 | number | number |
355+
| tst.ts:85:39:85:45 | boolean | boolean |
356+
| tst.ts:92:15:92:20 | number | number |
357+
| tst.ts:98:24:98:29 | number | number |
358+
| tst.ts:104:19:104:24 | string | string |
359+
| tst.ts:104:29:104:34 | hello | any |
360+
| tst.ts:104:37:104:42 | string | string |
361+
| tst.ts:109:22:109:27 | number | number |
362+
| tst.ts:109:29:109:29 | - | any |
363+
| tst.ts:109:32:109:37 | number | number |
364+
| tst.ts:109:39:109:39 | - | any |
365+
| tst.ts:109:42:109:47 | number | number |
366+
| tst.ts:110:19:110:25 | `1-2-3` | "1-2-3" |
367+
| tst.ts:110:19:110:25 | `1-2-3` | any |
368+
| tst.ts:111:22:111:27 | number | number |
369+
| tst.ts:111:29:111:32 | -2-3 | any |
370+
| tst.ts:117:20:117:25 | number | number |
371+
| tst.ts:121:23:121:28 | number | number |
291372
| type_alias.ts:1:6:1:6 | B | boolean |
292373
| type_alias.ts:1:10:1:16 | boolean | boolean |
293374
| type_alias.ts:3:8:3:8 | B | boolean |
@@ -360,13 +441,19 @@ referenceDefinition
360441
| Color.red | type_definitions.ts:14:3:14:5 | red |
361442
| E | type_definition_objects.ts:6:8:6:16 | enum E {} |
362443
| EnumWithOneMember | type_definitions.ts:18:26:18:31 | member |
444+
| Foo | tst.ts:116:3:129:3 | class F ... }\\n } |
363445
| HasArea | tst.ts:58:1:60:1 | interfa ... mber;\\n} |
364446
| I<S> | type_definitions.ts:3:1:5:1 | interfa ... x: S;\\n} |
365447
| I<number> | type_definitions.ts:3:1:5:1 | interfa ... x: S;\\n} |
366448
| Json | type_alias.ts:9:1:15:13 | type Js ... Json[]; |
367449
| MyUnion | tst.ts:65:1:65:54 | type My ... true}; |
368450
| MyUnion2 | tst.ts:68:1:68:49 | type My ... true}; |
369451
| NonAbstractDummy | tst.ts:54:1:56:1 | interfa ... mber;\\n} |
452+
| Sub | tst.ts:97:3:101:3 | class S ... }\\n } |
453+
| Super | tst.ts:91:3:95:3 | class S ... }\\n } |
454+
| Super | tst.ts:91:3:95:3 | class S ... }\\n } |
455+
| Thing | tst.ts:78:10:88:3 | class T ... }\\n } |
456+
| ThingI | tst.ts:73:3:76:3 | interfa ... n);\\n } |
370457
| ValueOrArray<T> | type_alias.ts:5:1:5:50 | type Va ... ay<T>>; |
371458
| ValueOrArray<number> | type_alias.ts:5:1:5:50 | type Va ... ay<T>>; |
372459
| VirtualNode | type_alias.ts:19:1:21:57 | type Vi ... ode[]]; |

javascript/ql/test/library-tests/TypeScript/Types/tst.ts

Lines changed: 62 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,4 +66,65 @@ type MyUnion = {myUnion: true} | {stillMyUnion: true};
6666
let union1: MyUnion = {myUnion: true};
6767

6868
type MyUnion2 = MyUnion | {yetAnotherType: true};
69-
let union2: MyUnion2 = {yetAnotherType: true};
69+
let union2: MyUnion2 = {yetAnotherType: true};
70+
71+
module TS43 {
72+
// TypeScript 4.3 setter/getter types
73+
interface ThingI {
74+
get size(): number
75+
set size(value: number | string | boolean);
76+
}
77+
78+
export class Thing implements ThingI {
79+
#size = 0;
80+
81+
get size(): number {
82+
return this.#size;
83+
}
84+
85+
set size(value: string | number | boolean) {
86+
this.#size = Number(value);
87+
}
88+
}
89+
90+
// overrides
91+
class Super {
92+
random(): number {
93+
return 4;
94+
}
95+
}
96+
97+
class Sub extends Super {
98+
override random(): number {
99+
return super.random() * 10;
100+
}
101+
}
102+
103+
// inference of template strings.
104+
function bar(s: string): `hello ${string}` {
105+
// Previously an error, now works!
106+
return `hello ${s}`;
107+
}
108+
109+
declare let s1: `${number}-${number}-${number}`;
110+
declare let s2: `1-2-3`;
111+
declare let s3: `${number}-2-3`;
112+
s1 = s2;
113+
s1 = s3;
114+
115+
// private methods
116+
class Foo {
117+
#someMethod(): number {
118+
return 42;
119+
}
120+
121+
get #someValue(): number {
122+
return 100;
123+
}
124+
125+
publicMethod() {
126+
this.#someMethod();
127+
return this.#someValue;
128+
}
129+
}
130+
}

0 commit comments

Comments
 (0)