Skip to content

Add extra test cases for string completions #54133

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
/// <reference path="fourslash.ts" />

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

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

verify.completions({ marker: ["ts"], exact: ["a", "b", "b.c"] });
verify.completions({ marker: ["ts"], exact: ["a", "b", "b.c"] });
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/// <reference path="fourslash.ts" />

// @strict: true

// repro from https://github.com/microsoft/TypeScript/issues/53997

//// type keyword = "foo" | "bar" | "baz"
////
//// type validateString<s> = s extends keyword
//// ? s
//// : s extends `${infer left extends keyword}|${infer right}`
//// ? right extends keyword
//// ? s
//// : `${left}|${keyword}`
//// : keyword
////
//// type isUnknown<t> = unknown extends t
//// ? [t] extends [{}]
//// ? false
//// : true
//// : false
////
//// type validate<def> = def extends string
//// ? validateString<def>
//// : isUnknown<def> extends true
//// ? keyword
//// : {
//// [k in keyof def]: validate<def[k]>
//// }
//// const parse = <def>(def: validate<def>) => def
//// const shallowExpression = parse("foo|/*ts*/")
//// const nestedExpression = parse({ prop: "foo|/*ts2*/" })

verify.completions({ marker: ["ts"], exact: ["foo", "bar", "baz", "foo|foo", "foo|bar", "foo|baz"] });
verify.completions({ marker: ["ts2"], exact: ["foo|foo", "foo|bar", "foo|baz"] });
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/// <reference path="fourslash.ts" />

// repro from https://github.com/microsoft/TypeScript/issues/49680#issuecomment-1249191842

//// declare function pick<T extends object, K extends keyof T>(obj: T, ...keys: K[]): Pick<T, K>;
//// declare function pick2<T extends object, K extends (keyof T)[]>(obj: T, ...keys: K): Pick<T, K[number]>;
////
//// const obj = { aaa: 1, bbb: '2', ccc: true };
////
//// pick(obj, 'aaa', '/*ts1*/');
//// pick2(obj, 'aaa', '/*ts2*/');

// repro from https://github.com/microsoft/TypeScript/issues/49680#issuecomment-1273677941

//// class Q<T> {
//// public select<Keys extends keyof T>(...args: Keys[]) {}
//// }
//// new Q<{ id: string; name: string }>().select("name", "/*ts3*/");

verify.completions({ marker: ["ts1", "ts2"], exact: ["aaa", "bbb", "ccc"] });
verify.completions({ marker: ["ts3"], exact: ["name", "id"] });