Sorry for the vague title, I'm struggling to articulate this idea.
Here is a type definition that I have:
type Foo = {
a: number,
b: string,
c: boolean,
}
I am looking to utilize this type as follows:
type FooInfo = {
property: keyof Foo,
description: string,
value: Foo[this.property]
}
The concept behind this type is that if property
is 'a', then the type of value
should be Foo[a]
(in this case, a 'number').
Here is an example demonstrating how this type works:
const propA = {
property: 'a',
description: 'This is a',
value: 5
}
I attempted using generics, but I want the type for value
to be deduced.
Is it possible to achieve this in Typescript?