json-schema-to-typescript
json-schema-to-typescript copied to clipboard
Get result without export
I'm generating types based on the api's schema which works. However the results contains a lot of export which forces me to explicitly import the generated types.
Since it's a Nuxt project (which comes with a nice auto-import feature) I'd like to have the generated types available without explicitly importing them. I've found an old issue that which relates to this topic though was (unfortunately) solved differently: https://github.com/bcherny/json-schema-to-typescript/issues/202
@bcherny it would be great to have an option to disable adding export
Can you expand on your use case a little more? It's generally an anti-pattern to use globals (values or types), and better to import types explicitly when you need them. Auto-import in VSCode also works fine with exported types.
Hi @bcherny, I have a use case about it.
Assume we have below strcutrure:
src/
json-schemas/
a.schema.json
b.schema.json
common.schema.json
types/
a.ts
b.ts
index.ts
I have two JSON Schema files, and they are independent but refer a shared common JSON schema. When I use the "json-schema-to-typescript" to generate two ts files and I export a.ts, b.ts in index.ts, like:
export * from './types/a';
export * from './types/b';
There are a TS errors show to tell me the common type is duplicated.
So I want to have the disable adding export feature.
I would love to have this as well. I'm using this library to generate types for a larger codegen purpose, where the types will be exposed as a generic parameter to a class instance that is exported. I don't need (or want) these types exported because they clutter up autocomplete in the IDE. Right now I'm just using regex to remove the export, but that doesn't feel like the best solution.
e.g.:
type GeneratedFromSchema = {
prop: string;
};
export const classInstance = new Class<GeneratedFromSchema>();