const func = <T>(
obj: T,
attr: keyof T,
arr: T[typeof attr][],
) => {
}
const obj = {foo: 1, bar: true};
func(obj, 'foo', [1]);
func(obj, 'bar', [1]); // shouln't be ok
func(obj, 'foo', [true]); // shouln't be ok
func(obj, 'bar', [true]);
Is there a way to define the type of argument arr
within the function func
so that TypeScript can correctly resolve it based on the actual value of attr
? I want the type of arr
to depend on the value of attr
, rather than always being number | boolean
.