joi-to-typescript icon indicating copy to clipboard operation
joi-to-typescript copied to clipboard

Configuring converted schema to be either a type or an interface

Open Ncifra opened this issue 1 year ago • 7 comments

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

Ncifra avatar Mar 01 '23 13:03 Ncifra

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

mrjono1 avatar Mar 01 '23 22:03 mrjono1

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.

Ncifra avatar Mar 03 '23 19:03 Ncifra

How did you go?

mrjono1 avatar Mar 28 '23 07:03 mrjono1

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.

Ncifra avatar Mar 28 '23 08:03 Ncifra

That makes sense

mrjono1 avatar Mar 28 '23 10:03 mrjono1

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

mrjono1 avatar Apr 13 '23 06:04 mrjono1

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.

Ncifra avatar Apr 13 '23 14:04 Ncifra