@bryce94/json-to-ts
Version:
将json转为ts声明
53 lines (52 loc) • 1.36 kB
TypeScript
import { Options } from 'prettier';
interface BaseType {
description?: string;
required?: boolean;
type: 'string' | 'number' | 'boolean' | 'null' | 'any';
alias?: string;
}
export type EnumItem = {
key?: string;
value: string | number;
description?: string;
};
interface EnumType {
description?: string;
type: 'enum';
required?: boolean;
alias?: string;
enum: EnumItem[];
}
interface ObjectType {
description?: string;
required?: boolean;
type: 'object';
alias?: string;
properties: {
[key: string]: BaseType | ObjectType | ArrayType | EnumType;
};
}
interface ArrayType {
description?: string;
required?: boolean;
type: 'array';
item: BaseType | ObjectType | ArrayType | EnumType;
alias?: string;
}
export type JSONType = BaseType | ObjectType | ArrayType | EnumType;
export type ParsedJSONType = BaseType | ObjectType | ArrayType | EnumType;
export type OptionsType = {
/** prettier配置 */
prettierOptions?: Options;
/** 声明拆分配置 */
abstractConfig?: Partial<IAbstractConfig>;
};
export type IAbstractConfig = {
/** 最大拆分深度 仅作用于object和array */
maxDepth: number;
/** 拆分类型 */
abstractType: Array<'object' | 'array'>;
/** 是否拆分枚举值 */
abstractEnum: boolean;
};
export {};