runtyping icon indicating copy to clipboard operation
runtyping copied to clipboard

Generics are not generated properly

Open AsPulse opened this issue 3 years ago • 3 comments

  • Same as #398 Issue was closed, but I tried and failed... Am I doing something wrong...?

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; }>,) =>

AsPulse avatar Sep 10 '22 02:09 AsPulse

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?

johngeorgewright avatar Sep 10 '22 09:09 johngeorgewright

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

AsPulse avatar Sep 11 '22 03:09 AsPulse

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 avatar Oct 12 '22 10:10 johngeorgewright