I have this interface:
interface Api {
state: Converter<State>;
water: Converter<Water>;
version: Converter<Versions>;
}
and I have a function called write
write(name, value);
now what I want to achieve is that the type of value should be the generic of Converter depending on the first parameter (name).
So if I call write("state", value) -> value should be State. The same goes for "water" and "version".
write("state, value); // value should be type of State
write("water", value); // value should be type of Water
write("version", value); // value should be type of Versions
I implemented the first parameter like so:
write(name: keyof Api, value: ???)
I found that I can get the corresponding value to keyof Api like so:
write<K extends keyof Api>(name: K, value: Api[K])
but that gives me Converter<State> for "state". Is there a way I can access the generic in Converter?