My issue is similar to the one described here and here (and probably other places too). I feel like it's a simple Lookup Type issue (documented here). But my use case is slightly different and I cannot get it to work.
I have a function that takes an object of Type and returns a "getter" function for this object.
Here's a simple playground.
type User = {
name: string,
age: number,
};
const makeGetter = <Type, Key extends keyof Type>(obj: Type) => (key: Key) => obj[key];
const user: User = {
age: 55,
name: 'Brian',
};
const getter = makeGetter(user);
const u = getter('age');
However, the selected property is always a union of all possible property types.
What am I missing?