Why is tsc complaining on this conditional type?

Viewed 46

Here is it :

type Foo<T, U> = U extends keyof T
    ? T[U] extends { root: string }
    ? T[U]['root'] : never  // not happy here
    : never

type a = Foo<{ k: { root: 'lala' } }, 'k'> // 'lala'  OK 

Why would the compiler complain even though he's able to return the right type ?

Edit: I have the problem with TS 4.5, with 4.6 and above this does not happen.

Playground

0 Answers
Related