From 99a509e6a4e1054226c8d4da01df6bf1afc5f5ff Mon Sep 17 00:00:00 2001 From: Arnau Sanchez Date: Mon, 16 Aug 2021 22:39:29 +0200 Subject: [PATCH] Convert TypeModel to a discriminated union type --- index.ts | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/index.ts b/index.ts index d8460a3..7b5e259 100644 --- a/index.ts +++ b/index.ts @@ -62,13 +62,10 @@ export enum TypeKind { UNION } -export interface TypeModel { - typeKind: TypeKind; +export type TypeModel = BasicType | ArrayType | UnionType; -} - -export interface BasicType extends TypeModel { - //typeName:string +export interface BasicType { + typeKind: TypeKind.BASIC; nameSpace: string; basicName: string; typeName: string; @@ -76,13 +73,15 @@ export interface BasicType extends TypeModel { modulePath: string; } -export interface ArrayType extends TypeModel { +export interface ArrayType { + typeKind: TypeKind.ARRAY; base: TypeModel; } -export type Arg = string|number|boolean; +export type Arg = string | number | boolean; -export interface UnionType extends TypeModel { +export interface UnionType { + typeKind: TypeKind.UNION; options: TypeModel[]; } @@ -174,4 +173,4 @@ export function classDecl(name: string, isInteface: boolean): ClassModel { export function parseStruct(content: string, modules: {[path: string]: Module}, mpth: string): Module { return tsStructureParser.parseStruct(content, modules, mpth); -} \ No newline at end of file +}