unjs / untyped

Generate types and markdown from a config object.
https://untyped.unjs.io/
MIT License
424 stars 19 forks source link

Support inline object definition with jsdocs `@typedef` #61

Open pi0 opened 1 year ago

pi0 commented 1 year ago

Ref: #54

Currently, we have basic @typedef support for defining type and then later mapping it to tstypes here (only for loader). typedef docs: https://jsdoc.app/tags-typedef.html

This feature can be enhanced by supporting inline object definitions with jsdocs notion with properties and useful for array object typing and defining shared types.

In order to implement this, we need to map the inline custom type from jsdocs, to json schema and then add it to the $defs and later check and map it for precise type resolution in typescript generator here

Alternatives:

pi0 commented 1 year ago

For reference: Using $schema to define directly as alternative to jsdocs for #54

https://untyped.unjs.io/#eyJlZGl0b3JUYWIiOiJyZWZlcmVuY2UiLCJvdXRwdXRUYWIiOiJ0eXBlcyIsInJlZiI6ImV4cG9ydCBkZWZhdWx0IHtcbiAgaWNvbkxpbmtzOiB7XG4gICAgJHNjaGVtYToge1xuICAgICAgdHlwZTogXCJhcnJheVwiLFxuICAgICAgaXRlbXM6IHtcbiAgICAgICAgdHlwZTogXCJvYmplY3RcIixcbiAgICAgICAgcHJvcGVydGllczoge1xuICAgICAgICAgIGljb246IHsgdHlwZTogXCJzdHJpbmdcIiwgZGVzY3JpcHRpb246IFwiaWNvbiBuYW1lXCIgfSxcbiAgICAgICAgICBocmVmOiB7XG4gICAgICAgICAgICB0eXBlOiBcInN0cmluZ1wiLFxuICAgICAgICAgICAgZGVzY3JpcHRpb246IFwiTGluayB3aGVuIGNsaWNraW5nIG9uIHRoZSBpY29uXCIsXG4gICAgICAgICAgfSxcbiAgICAgICAgICBsYWJlbDogeyB0eXBlOiBcIm51bWJlclwiLCBkZXNjcmlwdGlvbjogXCJMYWJlbCBvZiB0aGUgaWNvblwiIH0sXG4gICAgICAgIH0sXG4gICAgICB9LFxuICAgIH0sXG4gIH0sXG59O1xuIiwiaW5wdXQiOiJleHBvcnQgY29uc3QgY29uZmlnID0ge1xuICAgIG5hbWU6ICdmb28nLFxuICAgIGRpbWVuc2lvbnM6IHtcbiAgICAgICAgaGVpZ2h0OiAyNVxuICAgIH0sXG4gICAgdGFnczogWydjdXN0b20nXVxufSJ9