Skip to content

Wrong keyof behaviour for generic with extends types in 2.9 #24560

Closed
@mctep

Description

@mctep

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Design LimitationConstraints of the existing architecture prevent this from being fixed

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions