For example, I have an interface with properties: key and value, I want to infer value type by the key.
interface Obj { a: number; b: string }
interface Param<K extends keyof Obj> {
key: K
value: Obj[K] // I want to infer this type
}
const p: Param<keyof Obj> = {
key: 'a',
value: '', // typescript can't infer this type, expect number
}
How can I do that ?