-
Notifications
You must be signed in to change notification settings - Fork 12.8k
Update Pick to use new key remapping in mapped types #41383
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
Comments
I'm curious what would happen if we did that |
@RyanCavanaugh I ran the tests with the updated definition; 17 failed (11 conformance and 6 compiler). Looking at the baselines, I was able to distill one problem with the new definition to: type Pick<T, K extends keyof T> = { [P in keyof T as Extract<P, K>]: T[P] };
type Assert<T, U extends T> = U;
type X<T, K extends keyof T> = Assert<Pick<T, K>, T>;
// ^
// Errors, "Type 'T' does not satisfy the constraint 'Pick<T, K>'" I haven't looked through all of the baselines in detail to see if there are errors beyond that, though I suspect there are. Perhaps |
Also, what's the reasoning behind error 2312 (an interface can only extend an object type or intersection of object types with statically known members)? With the new type Record1<K extends keyof any, V> = { [_K in "" as K]: V }
interface RecordInterface<K extends keyof any, V> extends Record1<K, V> { } |
For one thing I noticed this fixes issues with You can see that passing an omit type into a remapped type causes an issue, but this new way of doing it fixes the issue. I wish I understood why, but perhaps someone could shed some light on it. |
@bfricka The problem in that scenario boils down to type Omit<T, K> = Pick<T, Exclude<keyof T, K>> Because #41966 looks like it might be relevant to your scenario. |
Search Terms
pick omit key remapping
Suggestion
Update
Pick
inlib.d.ts
to be:It is currently defined as:
Use Cases
With this new definition, typescript can statically analyze the keys, which allows interfaces to extends these types.
Examples
Playground Link
Checklist
My suggestion meets these guidelines:
The text was updated successfully, but these errors were encountered: