Allow lazily define type in annotations / ES modules
Opened this issue · 4 comments
Because of somewhat eager
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
git clone https://github.com/perceptron8/TypedJSONReferenceError
cd TypedJSONReferenceError
yarn install
yarn test
-> 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 of jsonMemberDecoratorFactory
- skipped at all?
This issue refers to: #139.
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 :)