gristlabs / ts-interface-checker

Runtime library to validate data against TypeScript interfaces.
Apache License 2.0
323 stars 18 forks source link

It looks like an interface with properties of that interface (recursive) is not supported #33

Closed zoechi closed 3 years ago

zoechi commented 3 years ago

The library looks great so far. Thanks for publishing! I run into a problem though:

export interface FormConfig {
  children?: FormConfig[];
 ● Test suite failed to run

    RangeError: Maximum call stack size exceeded

      at getNamedType (../../node_modules/.pnpm/ts-interface-checker@0.1.13/node_modules/ts-interface-checker/dist/types.js:33:22)
      at TName.Object.<anonymous>.TName.getChecker (../../node_modules/.pnpm/ts-interface-checker@0.1.13/node_modules/ts-interface-checker/dist/types.js:56:21)
      at ../../node_modules/.pnpm/ts-interface-checker@0.1.13/node_modules/ts-interface-checker/dist/types.js:329:79
          at Array.map (<anonymous>)
      at TIface.Object.<anonymous>.TIface.getChecker (../../node_modules/.pnpm/ts-interface-checker@0.1.13/node_modules/ts-interface-checker/dist/types.js:329:39)
      at TName.Object.<anonymous>.TName.getChecker (../../node_modules/.pnpm/ts-interface-checker@0.1.13/node_modules/ts-interface-checker/dist/types.js:57:29)
      at TArray.Object.<anonymous>.TArray.getChecker (../../node_modules/.pnpm/ts-interface-checker@0.1.13/node_modules/ts-interface-checker/dist/types.js:101:38)
      at ../../node_modules/.pnpm/ts-interface-checker@0.1.13/node_modules/ts-interface-checker/dist/types.js:329:79
          at Array.map (<anonymous>)
      at TIface.Object.<anonymous>.TIface.getChecker (../../node_modules/.pnpm/ts-interface-checker@0.1.13/node_modules/ts-interface-checker/dist/types.js:329:39)
      at TName.Object.<anonymous>.TName.getChecker (../../node_modules/.pnpm/ts-interface-checker@0.1.13/node_modules/ts-interface-checker/dist/types.js:57:29)
      at TArray.Object.<anonymous>.TArray.getChecker (../../node_modules/.pnpm/ts-interface-checker@0.1.13/node_modules/ts-interface-checker/dist/types.js:101:38)
      at ../../node_modules/.pnpm/ts-interface-checker@0.1.13/node_modules/ts-interface-checker/dist/types.js:329:79
          at Array.map (<anonymous>)
      at TIface.Object.<anonymous>.TIface.getChecker (../../node_modules/.pnpm/ts-interface-checker@0.1.13/node_modules/ts-interface-checker/dist/types.js:329:39)
      at TName.Object.<anonymous>.TName.getChecker (../../node_modules/.pnpm/ts-interface-checker@0.1.13/node_modules/ts-interface-checker/dist/types.js:57:29)
      at TArray.Object.<anonymous>.TArray.getChecker (../../node_modules/.pnpm/ts-interface-checker@0.1.13/node_modules/ts-interface-checker/dist/types.js:101:38)
      at ../../node_modules/.pnpm/ts-interface-checker@0.1.13/node_modules/ts-interface-checker/dist/types.js:329:79
          at Array.map (<anonymous>)
      at TIface.Object.<anonymous>.TIface.getChecker (../../node_modules/.pnpm/ts-interface-checker@0.1.13/node_modules/ts-interface-checker/dist/types.js:329:39)
      at TName.Object.<anonymous>.TName.getChecker (../../node_modules/.pnpm/ts-interface-checker@0.1.13/node_modules/ts-interface-checker/dist/types.js:57:29)
      at TArray.Object.<anonymous>.TArray.getChecker (../../node_modules/.pnpm/ts-interface-checker@0.1.13/node_modules/ts-interface-checker/dist/types.js:101:38)
      at ../../node_modules/.pnpm/ts-interface-checker@0.1.13/node_modules/ts-interface-checker/dist/types.js:329:79
          at Array.map (<anonymous>)
      at TIface.Object.<anonymous>.TIface.getChecker (../../node_modules/.pnpm/ts-interface-checker@0.1.13/node_modules/ts-interface-checker/dist/types.js:329:39)
      at TName.Object.<anonymous>.TName.getChecker (../../node_modules/.pnpm/ts-interface-checker@0.1.13/node_modules/ts-interface-checker/dist/types.js:57:29)
      at TArray.Object.<anonymous>.TArray.getChecker (../../node_modules/.pnpm/ts-interface-checker@0.1.13/node_modules/ts-interface-checker/dist/types.js:101:38)
      at ../../node_modules/.pnpm/ts-interface-checker@0.1.13/node_modules/ts-interface-checker/dist/types.js:329:79
          at Array.map (<anonymous>)
      at TIface.Object.<anonymous>.TIface.getChecker (../../node_modules/.pnpm/ts-interface-checker@0.1.13/node_modules/ts-interface-checker/dist/types.js:329:39)
      at TName.Object.<anonymous>.TName.getChecker (../../node_modules/.pnpm/ts-interface-checker@0.1.13/node_modules/ts-interface-checker/dist/types.js:57:29)
      at TArray.Object.<anonymous>.TArray.getChecker (../../node_modules/.pnpm/ts-interface-checker@0.1.13/node_modules/ts-interface-checker/dist/types.js:101:38)
      at ../../node_modules/.pnpm/ts-interface-checker@0.1.13/node_modules/ts-interface-checker/dist/types.js:329:79
          at Array.map (<anonymous>)
      at TIface.Object.<anonymous>.TIface.getChecker (../../node_modules/.pnpm/ts-interface-checker@0.1.13/node_modules/ts-interface-checker/dist/types.js:329:39)
      at TName.Object.<anonymous>.TName.getChecker (../../node_modules/.pnpm/ts-interface-checker@0.1.13/node_modules/ts-interface-checker/dist/types.js:57:29)
      at TArray.Object.<anonymous>.TArray.getChecker (../../node_modules/.pnpm/ts-interface-checker@0.1.13/node_modules/ts-interface-checker/dist/types.js:101:38)
      at ../../node_modules/.pnpm/ts-interface-checker@0.1.13/node_modules/ts-interface-checker/dist/types.js:329:79
          at Array.map (<anonymous>)
      at TIface.Object.<anonymous>.TIface.getChecker (../../node_modules/.pnpm/ts-interface-checker@0.1.13/node_modules/ts-interface-checker/dist/types.js:329:39)
      at TName.Object.<anonymous>.TName.getChecker (../../node_modules/.pnpm/ts-interface-checker@0.1.13/node_modules/ts-interface-checker/dist/types.js:57:29)
      at TArray.Object.<anonymous>.TArray.getChecker (../../node_modules/.pnpm/ts-interface-checker@0.1.13/node_modules/ts-interface-checker/dist/types.js:101:38)
      at ../../node_modules/.pnpm/ts-interface-checker@0.1.13/node_modules/ts-interface-checker/dist/types.js:329:79
          at Array.map (<anonymous>)
      at TIface.Object.<anonymous>.TIface.getChecker (../../node_modules/.pnpm/ts-interface-checker@0.1.13/node_modules/ts-interface-checker/dist/types.js:329:39)
      at TName.Object.<anonymous>.TName.getChecker (../../node_modules/.pnpm/ts-interface-checker@0.1.13/node_modules/ts-interface-checker/dist/types.js:57:29)
      at TArray.Object.<anonymous>.TArray.getChecker (../../node_modules/.pnpm/ts-interface-checker@0.1.13/node_modules/ts-interface-checker/dist/types.js:101:38)
      at ../../node_modules/.pnpm/ts-interface-checker@0.1.13/node_modules/ts-interface-checker/dist/types.js:329:79
          at Array.map (<anonymous>)
      at TIface.Object.<anonymous>.TIface.getChecker (../../node_modules/.pnpm/ts-interface-checker@0.1.13/node_modules/ts-interface-checker/dist/types.js:329:39)
      at TName.Object.<anonymous>.TName.getChecker (../../node_modules/.pnpm/ts-interface-checker@0.1.13/node_modules/ts-interface-checker/dist/types.js:57:29)
      at TArray.Object.<anonymous>.TArray.getChecker (../../node_modules/.pnpm/ts-interface-checker@0.1.13/node_modules/ts-interface-checker/dist/types.js:101:38)
      at ../../node_modules/.pnpm/ts-interface-checker@0.1.13/node_modules/ts-interface-checker/dist/types.js:329:79
          at Array.map (<anonymous>)
      at TIface.Object.<anonymous>.TIface.getChecker (../../node_modules/.pnpm/ts-interface-checker@0.1.13/node_modules/ts-interface-checker/dist/types.js:329:39)
      at TName.Object.<anonymous>.TName.getChecker (../../node_modules/.pnpm/ts-interface-checker@0.1.13/node_modules/ts-interface-checker/dist/types.js:57:29)
      at TArray.Object.<anonymous>.TArray.getChecker (../../node_modules/.pnpm/ts-interface-checker@0.1.13/node_modules/ts-interface-checker/dist/types.js:101:38)
      at ../../node_modules/.pnpm/ts-interface-checker@0.1.13/node_modules/ts-interface-checker/dist/types.js:329:79
          at Array.map (<anonymous>)
      at TIface.Object.<anonymous>.TIface.getChecker (../../node_modules/.pnpm/ts-interface-checker@0.1.13/node_modules/ts-interface-checker/dist/types.js:329:39)
      at TName.Object.<anonymous>.TName.getChecker (../../node_modules/.pnpm/ts-interface-checker@0.1.13/node_modules/ts-interface-checker/dist/types.js:57:29)
      at TArray.Object.<anonymous>.TArray.getChecker (../../node_modules/.pnpm/ts-interface-checker@0.1.13/node_modules/ts-interface-checker/dist/types.js:101:38)
      at ../../node_modules/.pnpm/ts-interface-checker@0.1.13/node_modules/ts-interface-checker/dist/types.js:329:79
          at Array.map (<anonymous>)
      at TIface.Object.<anonymous>.TIface.getChecker (../../node_modules/.pnpm/ts-interface-checker@0.1.13/node_modules/ts-interface-checker/dist/types.js:329:39)
      at TName.Object.<anonymous>.TName.getChecker (../../node_modules/.pnpm/ts-interface-checker@0.1.13/node_modules/ts-interface-checker/dist/types.js:57:29)
      at TArray.Object.<anonymous>.TArray.getChecker (../../node_modules/.pnpm/ts-interface-checker@0.1.13/node_modules/ts-interface-checker/dist/types.js:101:38)
      at ../../node_modules/.pnpm/ts-interface-checker@0.1.13/node_modules/ts-interface-checker/dist/types.js:329:79
          at Array.map (<anonymous>)
      at TIface.Object.<anonymous>.TIface.getChecker (../../node_modules/.pnpm/ts-interface-checker@0.1.13/node_modules/ts-interface-checker/dist/types.js:329:39)
      at TName.Object.<anonymous>.TName.getChecker (../../node_modules/.pnpm/ts-interface-checker@0.1.13/node_modules/ts-interface-checker/dist/types.js:57:29)
      at TArray.Object.<anonymous>.TArray.getChecker (../../node_modules/.pnpm/ts-interface-checker@0.1.13/node_modules/ts-interface-checker/dist/types.js:101:38)
      at ../../node_modules/.pnpm/ts-interface-checker@0.1.13/node_modules/ts-interface-checker/dist/types.js:329:79
          at Array.map (<anonymous>)
      at TIface.Object.<anonymous>.TIface.getChecker (../../node_modules/.pnpm/ts-interface-checker@0.1.13/node_modules/ts-interface-checker/dist/types.js:329:39)
      at TName.Object.<anonymous>.TName.getChecker (../../node_modules/.pnpm/ts-interface-checker@0.1.13/node_modules/ts-interface-checker/dist/types.js:57:29)
      at TArray.Object.<anonymous>.TArray.getChecker (../../node_modules/.pnpm/ts-interface-checker@0.1.13/node_modules/ts-interface-checker/dist/types.js:101:38)
      at ../../node_modules/.pnpm/ts-interface-checker@0.1.13/node_modules/ts-interface-checker/dist/types.js:329:79
          at Array.map (<anonymous>)
      at TIface.Object.<anonymous>.TIface.getChecker (../../node_modules/.pnpm/ts-interface-checker@0.1.13/node_modules/ts-interface-checker/dist/types.js:329:39)
      at TName.Object.<anonymous>.TName.getChecker (../../node_modules/.pnpm/ts-interface-checker@0.1.13/node_modules/ts-interface-checker/dist/types.js:57:29)
      at TArray.Object.<anonymous>.TArray.getChecker (../../node_modules/.pnpm/ts-interface-checker@0.1.13/node_modules/ts-interface-checker/dist/types.js:101:38)
      at ../../node_modules/.pnpm/ts-interface-checker@0.1.13/node_modules/ts-interface-checker/dist/types.js:329:79
          at Array.map (<anonymous>)
      at TIface.Object.<anonymous>.TIface.getChecker (../../node_modules/.pnpm/ts-interface-checker@0.1.13/node_modules/ts-interface-checker/dist/types.js:329:39)
      at TName.Object.<anonymous>.TName.getChecker (../../node_modules/.pnpm/ts-interface-checker@0.1.13/node_modules/ts-interface-checker/dist/types.js:57:29)
      at TArray.Object.<anonymous>.TArray.getChecker (../../node_modules/.pnpm/ts-interface-checker@0.1.13/node_modules/ts-interface-checker/dist/types.js:101:38)
      at ../../node_modules/.pnpm/ts-interface-checker@0.1.13/node_modules/ts-interface-checker/dist/types.js:329:79
          at Array.map (<anonymous>)
      at TIface.Object.<anonymous>.TIface.getChecker (../../node_modules/.pnpm/ts-interface-checker@0.1.13/node_modules/ts-interface-checker/dist/types.js:329:39)
      at TName.Object.<anonymous>.TName.getChecker (../../node_modules/.pnpm/ts-interface-checker@0.1.13/node_modules/ts-interface-checker/dist/types.js:57:29)
      at TArray.Object.<anonymous>.TArray.getChecker (../../node_modules/.pnpm/ts-interface-checker@0.1.13/node_modules/ts-interface-checker/dist/types.js:101:38)
      at ../../node_modules/.pnpm/ts-interface-checker@0.1.13/node_modules/ts-interface-checker/dist/types.js:329:79
          at Array.map (<anonymous>)
      at TIface.Object.<anonymous>.TIface.getChecker (../../node_modules/.pnpm/ts-interface-checker@0.1.13/node_modules/ts-interface-checker/dist/types.js:329:39)
      at TName.Object.<anonymous>.TName.getChecker (../../node_modules/.pnpm/ts-interface-checker@0.1.13/node_modules/ts-interface-checker/dist/types.js:57:29)
      at TArray.Object.<anonymous>.TArray.getChecker (../../node_modules/.pnpm/ts-interface-checker@0.1.13/node_modules/ts-interface-checker/dist/types.js:101:38)
      at ../../node_modules/.pnpm/ts-interface-checker@0.1.13/node_modules/ts-interface-checker/dist/types.js:329:79
          at Array.map (<anonymous>)
      at TIface.Object.<anonymous>.TIface.getChecker (../../node_modules/.pnpm/ts-interface-checker@0.1.13/node_modules/ts-interface-checker/dist/types.js:329:39)

Is this a known issue? Is there a workaround?

dsagal commented 3 years ago

Interesting! I don't think it was a known issue, probably only because no one had used ts-interface-checker with a recursive interface. But now that you bring it up, it should've been expected.

I don't know of an easy workaround, I think we'll need to fix it in code.

zoechi commented 3 years ago

That would be great. We could make these properties object and then cast when accessed, but these properties are not too surprisingly exactly these where the checks are most important.

zoechi commented 3 years ago

Thanks a lot! The last update solves the biggest hurdles. Super useful package \o/