Error with 'never' type when using extends keyof as generic type

Viewed 1064

My code in typescript:

class Author {
  id: number;
}
type Getter<S, A> = (obj: S) => A;

function propGetter<S, K extends keyof S>(prop: K): Getter<S, S[K]> {
  return o => o[prop];
}
const _id: Getter<Author, number> = propGetter('id');

I got error:

Argument of type '"id"' is not assignable to parameter of type 'never'.

Code in typescript playground

As far as I understand, type K should be strings of keys of type S. How it's unified to never? It's because using mapped type as generic param?

1 Answers
Related