mrjono1 / joi-to-typescript

Convert Joi Schemas to TypeScript interfaces
MIT License
125 stars 39 forks source link

Configuring converted schema to be either a type or an interface #307

Open Ncifra opened 1 year ago

Ncifra commented 1 year ago

Hi,

We are trying to solve this issue, and one way would be to use a type instead of an interface when defining strict types. Is there any way to configure joi-to-typescript to force the generation of a type instead of an interface?

Thanks

mrjono1 commented 1 year ago

It might be possible try changing this line to type and see what happens https://github.com/mrjono1/joi-to-typescript/blob/master/src/parse.ts#L161

Ncifra commented 1 year ago

Thanks, I will try this and let you know since I moved to some other issues. From the looks of it, that would work though.

Can you please leave this open until I get back to this? Also, if that change would do it, will that be part of some update, or would there be some way to configure or "hack" it as it is from the Joi schema.

mrjono1 commented 1 year ago

How did you go?

Ncifra commented 1 year ago

Hey Jono,

Sorry for the wait. So I tried this now, changed the line inside node_modules, in parse.js, and it "worked", so instead of interface it replaced the text to type, but it's not a correct type, since the type would need to be something like: type Something = {} instead of now which is like an interface: type Something {}.

I guess that it would need to be a bit more explicitly coded for that.

mrjono1 commented 1 year ago

That makes sense

mrjono1 commented 1 year ago

would you want everything to be a type instead of an interface or just some of them?

Ncifra commented 1 year ago

I guess it would be good to be configurable as an option/parameter for backwards compatibility at least. I am not sure if changing all existing interface files to type ones will be safe.