Closed
Description
TypeScript Version: 2.9.1, 3.0.0-dev.20180601
Search Terms: keyof 2.9 generics extract extends string number symbol
Code
type StringKeyof<T> = Extract<keyof T, string>;
type Omit<T, K extends StringKeyof<T>> = any;
type WithoutFoo = Omit<{ foo: string }, "foo">; // ok
type WithoutFooGeneric<P extends { foo: string }> = Omit<P, "foo">; // Error: Type '"foo"' does not satisfy the constraint 'Extract<keyof P, string>'.
Expected behavior:
Omit
should pass "foo"
as valid type for keyof because generic type extends a type that has this string key.
Actual behavior:
Error: Type '"foo"' does not satisfy the constraint 'Extract<keyof P, string>'.
Playground Link: Link