-
Notifications
You must be signed in to change notification settings - Fork 65
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
Allow lazily define type in annotations / ES modules #189
Comments
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 MatthiasKunnen/TypedJSONReferenceError@f8703fd. 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 :) |
For anyone blocked by TypedJSON issues: my own software heavily relied on TypedJSON and had to apply numerous hacks for issues in TypedJSON that are not getting fixed. I loved TypedJSON but unfortunately had to move on as there has not been a single fix in 4 years now. Therefore I created the similarly powerful library json-class-serializer heavily inspired by TypedJSON, which addresses all my issues (and hopefully yours). It's pretty much a drop-in replacement if you don't rely on reflect-metadata, which I'm not supporting (as this was the cause of most of my issues). If you rely on reflect-metadata, just specify the constructors of properties other than string/number/boolean and then it most likely just works. Please feel free to give it a try if you feel the urge to move away from TypedJSON but don't want to do any heavy re-engineering. And please don't hate on me for the advertisement here as I have contributed to TypedJSON as well and opened many still-open issues :-). You can find my library at @sumbricht/json-class-serializer and gladly open issues there if you feel something's missing / not working correctly. |
Because of somewhat eager
TypedJSON/src/json-member.ts
Line 195 in 6f886ae
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 microsoft/TypeScript#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:
TypedJSON/tsconfig/tsconfig.spec.json
Line 4 in 6f886ae
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.
The text was updated successfully, but these errors were encountered: