Can you define properties of an object based on another property within the same object?
How do I determine the types for values
based on the value of the type
property?
type StepKeys = "Test1" | "Test2";
interface objectMap {
"Test1": {
name: string
},
"Test2": {
age: number
}
};
interface Step<T extends StepKeys = StepKeys> {
type: T;
value: objectMap[T]
};
const steps: Record<string, Step> = {
"Step1": {
type: "Test1",
value: {
}
}
}
The possible types for values
are a union of
{ name: string; } | { age: number; }
.
Is it feasible to deduce its potential values?