MasatoDev / boostest

14 stars 0 forks source link

Support nested types. #19

Closed MasatoDev closed 2 months ago

MasatoDev commented 2 months ago

Support nested types.

export type NestedType = {
  a: number;
  b: string;
  c: {
    d: boolean;
    e: {
      f: number;
      g: string;
      h: {
        i: number;
        j: {
          k: boolean;
          l: string[];
        };
      };
    };
    m: {
      n: number[];
      o: string;
    };
  };
  p: {
    q: {
      r: number;
    };
    s: {
      t: boolean;
      u: {
        v: number;
        w: string;
      };
    };
  };
  x: (number | string)[];
  y: Record<string, { z: number; aa: boolean }>;

  // Addition of type literals
  literalType: 'option1' | 'option2' | 'option3';
  mixedType: { a: number } & { b: string }; // Intersection type
  conditionalType: 'active' | 'inactive' | { status: 'pending'; detail: string };

  extended: {
    id: number;
    info: {
      description: string;
      tags: ('tag1' | 'tag2' | 'tag3')[]; // Array of literal types
      settings: {
        mode: 'auto' | 'manual';
        level: 1 | 2 | 3; // Literal type (specific numbers)
        extras?: {
          feature: true | false;
        };
      };
    };
  };
};

Currently, The above results in the following, showing that nested types are not output.

    + export function boostestNestedType<T>(args?: Partial<T>): T {
    +   return ({
    +           'a':10,
    +           'b':'test string data',
    +           'c':{},
    +           'p':{},
    +           'x':[],
    +           'y':{},
    +           'literalType':'option1',
    +           'mixedType':{},
    +           'conditionalType':'active',
    +           'extended':{},
    +           ...args
    +   } as T);
    + }
    +