I'd like a way to have an interface with a single generic, in which a property is keyof T and the other is the proper T[keyof T] passed on the first property.
The following code almost meets this requirement, correctly typing the first property (field):
interface RandomType {
foo: string;
bar: number;
baz: boolean;
}
type Typer<T = Record<string, any>> = {
field: keyof T,
value: T[any]
}
const param: Typer<RandomType> = {
field: 'baz',
value: 'foo'
}
However, I need to type value based on field's value
in the previous example, it should trigger a type error because RandomType['baz'] is boolean