Skip to content

Commit e3732af

Browse files
committed
Add extra test cases for string completions
1 parent ef50d45 commit e3732af

3 files changed

+58
-3
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
/// <reference path="fourslash.ts" />
22

3-
// NOTE: Test pulled from https://github.com/microsoft/TypeScript/pull/52997
3+
// repro from https://github.com/microsoft/TypeScript/issues/49680
44

5-
// @Filename: /a.tsx
65
//// type PathOf<T, K extends string, P extends string = ""> =
76
//// K extends `${infer U}.${infer V}`
87
//// ? U extends keyof T ? PathOf<T[U], V, `${P}${U}.`> : `${P}${keyof T & (string | number)}`
@@ -12,4 +11,4 @@
1211
////
1312
//// consumer('b./*ts*/')
1413

15-
verify.completions({ marker: ["ts"], exact: ["a", "b", "b.c"] });
14+
verify.completions({ marker: ["ts"], exact: ["a", "b", "b.c"] });
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/// <reference path="fourslash.ts" />
2+
3+
// @strict: true
4+
5+
// repro from https://github.com/microsoft/TypeScript/issues/53997
6+
7+
//// type keyword = "foo" | "bar" | "baz"
8+
////
9+
//// type validateString<s> = s extends keyword
10+
//// ? s
11+
//// : s extends `${infer left extends keyword}|${infer right}`
12+
//// ? right extends keyword
13+
//// ? s
14+
//// : `${left}|${keyword}`
15+
//// : keyword
16+
////
17+
//// type isUnknown<t> = unknown extends t
18+
//// ? [t] extends [{}]
19+
//// ? false
20+
//// : true
21+
//// : false
22+
////
23+
//// type validate<def> = def extends string
24+
//// ? validateString<def>
25+
//// : isUnknown<def> extends true
26+
//// ? keyword
27+
//// : {
28+
//// [k in keyof def]: validate<def[k]>
29+
//// }
30+
//// const parse = <def>(def: validate<def>) => def
31+
//// const shallowExpression = parse("foo|/*ts*/")
32+
//// const nestedExpression = parse({ prop: "foo|/*ts2*/" })
33+
34+
verify.completions({ marker: ["ts"], exact: ["foo", "bar", "baz", "foo|foo", "foo|bar", "foo|baz"] });
35+
verify.completions({ marker: ["ts2"], exact: ["foo|foo", "foo|bar", "foo|baz"] });
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/// <reference path="fourslash.ts" />
2+
3+
// repro from https://github.com/microsoft/TypeScript/issues/49680#issuecomment-1249191842
4+
5+
//// declare function pick<T extends object, K extends keyof T>(obj: T, ...keys: K[]): Pick<T, K>;
6+
//// declare function pick2<T extends object, K extends (keyof T)[]>(obj: T, ...keys: K): Pick<T, K[number]>;
7+
////
8+
//// const obj = { aaa: 1, bbb: '2', ccc: true };
9+
////
10+
//// pick(obj, 'aaa', '/*ts1*/');
11+
//// pick2(obj, 'aaa', '/*ts2*/');
12+
13+
// repro from https://github.com/microsoft/TypeScript/issues/49680#issuecomment-1273677941
14+
15+
//// class Q<T> {
16+
//// public select<Keys extends keyof T>(...args: Keys[]) {}
17+
//// }
18+
//// new Q<{ id: string; name: string }>().select("name", "/*ts3*/");
19+
20+
verify.completions({ marker: ["ts1", "ts2"], exact: ["aaa", "bbb", "ccc"] });
21+
verify.completions({ marker: ["ts3"], exact: ["name", "id"] });

0 commit comments

Comments
 (0)