我希望能够使用TypeScript
来分析JSON对象并输出接口。
我尝试动态的目的是转换JSON,如下所示:
{
"foo": "some string value",
"bar": 5,
"baz": {
"a": "string"
},
"baz2": {
"a": "string"
}
}
调用可能存在或不存在的此类函数:
typescript.doSomeMagic(objFromAbove);
// or
typescript.doSomeMagic(JSON.stringify(objFromAbove));
让它输出一个接口(或接口):
interface IProvidedName {
foo: string;
bar: number;
baz: { a: string; b: number; }
baz2: IBaz2;
}
interface IBaz2 {
a: string;
}
我可以使用baz
或上面baz2
的格式。
我目前正在挖掘寻找对象推理函数的typescript模块。
答案 0 :(得分:3)
我正在挖掘寻找对象推理函数的typescript模块。
有一个工具json2dts:http://xperiments.in/json2dts/
它也被整合到atom-typescript中:https://github.com/TypeStrong/atom-typescript/pull/466