TypeScript 提供了静态类型检查,带来了以下好处:git
开发过程当中须要更多的类型,以让 TypeScript 的效果更好,特别是先后端协做时,将接口文档信息转换为 TypeScript 类型声明,来保证项目质量。 可是手动的根据后端接口文档进行编辑,带来很高的编辑成本。github
typeof-jsonc lib 库支持将 jsonc
字符串转换为 TS 声明typescript
待转换接口示例json
{
"code": 0,
"data": {
// this is name
"name": "hello",
// this is age
"age": 18
},
"msg": "success"
}
复制代码
typeof-jsonc
转换结果后端
export interface IResponseData {
code: number;
data: IData;
msg: string;
}
export interface IData {
/** * this is name */
name: string;
/** * this is age */
age: number;
}
复制代码
线上工具截图数组