json2type
v0.0.6
Published
json2type
Downloads
29
Maintainers
Readme
介绍
json2type
通过一套 json 协议自动生成 ts 类型
功能
支持以下 ts 类型的转换
- String
- Number
- Boolean
- Any
- Never
- Undefined
- Null
- Void
- Object
- Array
- Intersection
- Union
- Tuple
- Enum
快速开始
tnpm install json2type
// 简单的例子
const json2type= require('json2type')
json2type({
type: 'Number',
description: '测试number',
name: 'b',
required: true,
children: []
})
// res ->
// 测试number
export type B = number;
API
- json2type
declare const json2type: (json: Json2type) => string;
- genSplitTypes
declare const genSplitTypes: (json: Json2type) => string;
json 协议
export interface Json2type{
// 类型
type: 'String' | 'Number' | 'Boolean' | 'Any' | 'Never' | 'Undefined' | 'Null' | 'Void' | 'Object' | 'Array' | 'Intersection' | 'Union' | 'Tuple' | 'Enum';
// 注释
description?: string;
// key
name: string;
// 是否一直存在
required?: boolean;
// 子节点
children: Json2type[];
// 值
value?: string | number
}