【发布时间】:2017-12-14 21:49:51
【问题描述】:
我想创建一个对象,其中属性名称是联合类型的值,值的类型基于该道具类型,例如:
type Direction =
"horizontal"
| "vertical"
| "diagonal"
;
// Choose one of this types based on Direction option
interface HorizontalData { foo: number; }
interface VerticalData { bar: string; }
interface DiagonalData { baz: boolean; }
type Result<D extends Direction> = {
data: << type based on D value >>;
};
【问题讨论】:
标签: typescript