microsoft / dts-gen

dts-gen creates starter TypeScript definition files for any module or library.
MIT License
2.43k stars 101 forks source link

Is there a way to configure this for "relaxed" type generation? #191

Open unphased opened 7 months ago

unphased commented 7 months ago

I have some large and deep javascript structures I generate in my app as a database of sorts.

Now I want to have a type def for it since it turns out I got pretty used to getting the editor suggesting types for me, and I probably should handcraft a type def, but I am exploring autogenerating this thing based on the dynamic value I generate in my app.

The problem with this is that dts-gen is way too strict. I have objects whose keys are file paths, and so it's generating types that have all these file paths serialized out. Now this is not surprising and correct behavior but I wonder if there is some sort of thing I can do to cause it to just use e.g. string in this situation? And for all the differences in the child properties, resolve them down to required or optional types based on whether they are always present or sometimes present.

I assume this is probably possible but nobody really has built such a thing. I guess I will bite the bullet and hand craft and maintain the type.