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

Exporting static types even when "exportStaticType" is false #313

Open
sstur opened this issue Jul 8, 2022 · 3 comments
Open

Exporting static types even when "exportStaticType" is false #313

sstur opened this issue Jul 8, 2022 · 3 comments
Labels
bug Something isn't working

Comments

@sstur
Copy link

sstur commented Jul 8, 2022

This doesn't happen in all cases, but it seems to be the case with a tagged union. I have a one-click repro for you to check out here: https://stackblitz.com/edit/node-5bqrlm?file=src/main.ts

The source types in that example looks like this:

Click to expand
type One = {
  type: 'one';
  value: string;
};

type Two = {
  type: 'two';
  value: number;
};

export type Three = One | Two;

You'll see the generated output is at "src/generated/runtypes.ts" which was generated by running ts-node src/main.ts and it looks like this:

Click to expand
import { Record, Literal, String, Static, Number } from 'runtypes';

export const One = Record({ type: Literal("one"), value: String, });

export type One = Static<typeof One>;

export const Two = Record({ type: Literal("two"), value: Number, });

export type Two = Static<typeof Two>;

export const Three = One.Or(Two);

Notice in main.ts I only asked for the type Three (which is the only exported member in types.ts) and I also specified exportStaticType: false, yet I got 6 exports in the generated output, 3 of which are types.

Any idea why this would be? If you can confirm this is a bug and if you could point me in the right direction I might be able to get a PR together.

Thanks!

@johngeorgewright
Copy link
Owner

johngeorgewright commented Jul 11, 2022

Runtypes One & Two have been generated as they are dependents of Three and all runtypes are exported by default. If you can think of a scenario in which exporting the dependents is a problem we can look in to changing that.

The fact that the static types are being generated, even when configured not to do so, looks like a bug.

@sstur
Copy link
Author

sstur commented Jul 12, 2022

all runtypes are exported by default. If you can think of a scenario in which exporting the dependents is a problem we can look in to changing that

OK, makes sense, I didn't realize that. In most cases this isn't an issue, the only very minor thing is that when editing other files VS Code will populate auto-complete suggestions based on exports of files in the same project, so it creates a bit more noise in that situation.

The fact that the static types are being generated, even when configured not to do so, looks like a bug.

Got it, happy to help come up with a solution if I can.

@johngeorgewright johngeorgewright added the bug Something isn't working label Jul 12, 2022
johngeorgewright added a commit that referenced this issue Jul 12, 2022
Make sure to pass reference to settings during recursion.

#313
@johngeorgewright
Copy link
Owner

Problems with excluding static type exports fixed in 4.6.0.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants