Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Get result without export #492

Open
SassNinja opened this issue Oct 13, 2022 · 3 comments
Open

Get result without export #492

SassNinja opened this issue Oct 13, 2022 · 3 comments

Comments

@SassNinja
Copy link

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: #202

@bcherny it would be great to have an option to disable adding export

@bcherny
Copy link
Owner

bcherny commented Jan 21, 2023

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.

@chasewoo
Copy link

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.

@apottere
Copy link

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>();

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants