typeonly icon indicating copy to clipboard operation
typeonly copied to clipboard

Support for Generics

Open shane-lab opened this issue 5 years ago • 0 comments

Hi,

This is one of the only library that I have come across that does what I need it to do: parse definitions to json (schemas).

Awesome!

I am facing one problem, and that is the ability to be able to parse custom type definitions with one or more generic types. I aware, at least from what I can guess, that this is meant for staticly typed defintions.

I use generic types extensively. I can workaround most of them, but there are some scenarios where I rather do not. Here's a simplified example:

// types/index.d.ts
export type DeepPartial<T> = { [P in keyof T]?: DeepPartial<T[P]> }

// types/x.d.ts
interface X {
  a: string,
  b: boolean,
  c?: number,
  d: {
    e: any,
    f: any,
    g: any,
  },
}
export type DetailsX = DeepPartial<X>

// src/create-or-update-x.ts
const upsertWithX = (x: DetailsX): X => ...;

I wonder what your thoughts are for generating a JSON mapping for DetailsX (ideally DeepPartial<X>).

shane-lab avatar Feb 07 '20 15:02 shane-lab