Closed
Description
I'm not sure why the Pick type has the keyof T
constraint although the Omit type doesn't have.
TypeScript Version: 3.7.x-dev.20200107
Search Terms:
Code
const sym = Symbol();
class C {
p = 0;
[sym]: '';
}
type a = Pick<C, symbol>;
type b = Omit<C, string>;
type Structural<T> = Pick<T, string | number>;
Expected behavior:
pass
type Pick<T, K extends string | number | symbol> = { [P in Extract<keyof T, K>]: T[P]; };
type Omit<T, K extends string | number | symbol> = { [P in Exclude<keyof T, K>]: T[P]; }
Actual behavior:
Type 'symbol' does not satisfy the constraint 'unique symbol | "p"'.(2344)
Type 'string | number' does not satisfy the constraint 'keyof T'.
Type 'string' is not assignable to type 'keyof T'.(2344)
type Pick<T, K extends keyof T> = { [P in K]: T[P]; }
type Omit<T, K extends string | number | symbol> = { [P in Exclude<keyof T, K>]: T[P]; };
Related Issues: