MariusAlch/json-to-ts

How to export the interfaces?

Closed this issue · 1 comments

I think there needs to be a flag for prepending export ... to the interface to be able to import it from other files.

I'm using this in tests, to automatically write the interface to a file. But on subsequent runs the file gets overwritten. If I add export manually, it gets overwritten.

Thanks

I would suggest trying something like this.

const json  = {hello: "world"}
const types = JsonToTS(json).map(type => type.replace('interface', 'export interface').join("\n\n"))
console.log(types)