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

Generics are not generated properly #407

Open
AsPulse opened this issue Sep 10, 2022 · 3 comments
Open

Generics are not generated properly #407

AsPulse opened this issue Sep 10, 2022 · 3 comments
Labels
bug Something isn't working

Comments

@AsPulse
Copy link

AsPulse commented Sep 10, 2022

Generated:

Record({ abc: <{ data: string; } extends any, > ({ data: string; }: Runtype<{ data: string; }>,) => Record({ data: String, }).And(Record({ count: Number, })),});

I don't think the bottom part is necessary and gills in my opinion. Is it necessary for some generative process...?
<{ data: string; } extends any, > ({ data: string; }: Runtype<{ data: string; }>,) =>

@johngeorgewright
Copy link
Owner

Hey @AsPulse. I just tried your example in #398, but I get a different result to what you're saying here.
https://stackblitz.com/edit/node-atzfxo?file=src/index.runtypes.ts
Can you provide me with a full example?

@AsPulse
Copy link
Author

AsPulse commented Sep 11, 2022

Sorry, I checked and it seems that the problem only occurs when importing a Type containing Generics from another file (external.ts in the example below).

https://stackblitz.com/edit/node-ahtzsa?file=src/external.ts

@johngeorgewright
Copy link
Owner

So, finally got around to having a look at this. The problem boils down to a bug when importing types from other files. It's a toughy, and I'll get around to it soon. In the mean time, if at all possible, the work around is to specify the source file of the type you're trying to build.

Instead of:

- targetFile: ./src/index.runtypes.ts
  sourceTypes:
    - file: ./src/index.ts
      type: [Foo]

Use:

- targetFile: ./src/index.runtypes.ts
  sourceTypes:
    - file: ./src/external.ts
      type: [Bar]

@johngeorgewright johngeorgewright added the bug Something isn't working label Oct 12, 2022
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