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'.
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?