Nested infer returns unknown on conditional type

29 views Asked by At

My code will speak better that my words:

type Id<T> = { [P in keyof T]: T[P] }
type RemoveMethods<T> = { [P in keyof T as T[P] extends (...args: any) => any ? never : P]: T[P] }

type Foo = Bar<{ title: string }>

export declare class Bar<T> {
    foo: string;
    fn1(arg: T): T
}

type Baz = Foo extends Id<Bar<infer U>> ? U : never; // OK
//   ^?

type Baz2 = Foo extends RemoveMethods<Bar<infer U>> ? U : never; // KO
//   ^?

type Baz3 = Foo extends Bar<infer U> ? U : never; // KO
//   ^?

Why does the infer fails to return { title: string } when using RemoveMethods.

Playground

0

There are 0 answers