Open perceptron8 opened 2 years ago
I had the same problem. It was a real headache.
Hi, I'm the author of the PR that introduced support for circular dependencies to this library. I had hoped to become a maintainer and improve this library further but unfortunately, the owner is not receptive to breaking changes and very slow to respond. This lead to my implementation being amended with imperfect backwards compatibility.
Since then, I have forked the library to https://github.com/decoverto/decoverto and reworked the code; simplified options, increased test coverage to 100%, better lazy types implementation, better inheritance support, and much more.
Modifying your reproduction to use Decoverto succeeds for me @perceptron8. See https://github.com/MatthiasKunnen/TypedJSONReferenceError/commit/f8703fdc9e70cf6c8dbcc2f8644da7fafdd3a86b.
Perhaps using Decoverto can help you.
@MatthiasKunnen Thanks for letting me know! :) https://github.com/JohnWeisz/TypedJSON doesn't seem to be very much alive.
Because of deadlines, I had to write TS<->JSON parsing / serializing library from scratch. Unfortunately I'm not allowed to share it as I wasn't writing it in my private time (this lib is now property of a company I work in).
I hope that https://github.com/decoverto/decoverto relieves at least @AnkoGo123's pain ;)
Thanks again and good luck!
@perceptron8 Thank you!
It's a shame I missed this issue a year ago, perhaps I could've saved you the effort of creating your own library. If at any time in the future you have a need for another serialization library perhaps we'll meet again :)
Because of somewhat eager https://github.com/JohnWeisz/TypedJSON/blob/6f886ae669c351c6dfc3d02e853bc6294cf3d054/src/json-member.ts#L195 it's currently impossible to define types truly lazily. Above call causes serious problems when ES modules are being used.
To reproduce, you can review and
->
ReferenceError: Cannot access 'A' before initialization
."emitDecoratorMetadata" (tsconfig.json) is deliberately set to false, so it's not because of https://github.com/microsoft/TypeScript/issues/4521.
If you change "type" to "commonjs" (package.json) and "compilerOptions" / "module" to "CommonJS" (tsconfig.json), test will run fine. BTW that's exactly why your lazy-types.spec.ts isn't failing: https://github.com/JohnWeisz/TypedJSON/blob/6f886ae669c351c6dfc3d02e853bc6294cf3d054/tsconfig/tsconfig.spec.json#L4
I know that
typeToTest
is currently being used to check for special property types, but maybe this checking could be deferred or - in case ofjsonMemberDecoratorFactory
- skipped at all?This issue refers to: #139.