Search Terms
pick omit key remapping
Suggestion
Update Pick in lib.d.ts to be:
type Pick<T, K extends keyof T> = {
[P in keyof T as Extract<P, K>]: T[P];
};
It is currently defined as:
type Pick<T, K extends keyof T> = {
[P in K]: T[P];
};
Use Cases
With this new definition, typescript can statically analyze the keys, which allows interfaces to extends these types.
Examples
interface Base {
a: number,
b: string,
c: boolean,
}
// Errors: "An interface can only extend an object type or intersection of object types with statically known members"
interface PickBase0<K extends keyof Base> extends Pick<Base, K> {
pickedKeys: K
}
type Pick1<T, K extends keyof T> = { [L in keyof T as Extract<L, K>]: T[L] }
// Works
interface PickBase1<K extends keyof Base> extends Pick1<Base, K> {
pickedKeys: K
}
Playground Link
Checklist
My suggestion meets these guidelines:
Search Terms
pick omit key remapping
Suggestion
Update
Pickinlib.d.tsto 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: