如何在对象上应用接口

时间:2019-05-10 15:28:35

标签: typescript casting

我有一个带有某些字段的接口,某些字段的类型本身就是接口。

例如:

interface IA {
    b: string;
    c: string;
    d: ID;
}

interface ID {
    e: number;
    f: boolean;
}

我有一个看起来像这样的对象

{ b: "b", c: "c", d: { e: "2", f: "true" } }

我想在该对象上转换/应用该接口,以便最终看起来像这样:

{ b: "b", c: "c", d: { e: 2, f: true } }

是否有内置的方法来实现?或任何其他解决方案来实现它?

预先感谢

0 个答案:

没有答案