fix(classes): fixed transformer ttypescript / ts-patch support #556
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Hello.
I got a bug report on ts-patch:
Upon investigating, I found that it had to do with an issue in the @automapper/classes/transformer-plugin transformer.
The issue seems to be that the instructions are incorrect for use with
ttypescript
/ts-patch
, and there is currently no export which would work with them.Background
For some background, I wrote ts-patch, which was in parallel to
ttypescript
for a while.After some time, tts wasn't being maintained any more, but users would open PRs to propagate my logic in. More recently, ttypescript has effectively been deprecated, as it no longer supports TS v5+, and it seems there are no plans to.
I did significant rewrites to ts-patch, where it's diverged too much for it to be propagated in, and it also now has an in-memory compiler, so tts is no longer needed.
Changes
I made three changes.
First, the signature of your default export was in a format that wouldn't work for
ttypescript
orts-patch
. You can see the signatures here:Essentially, we're looking for a transformer factory. Our default is the "program" type.
Your
before
export almost would have worked, but the order of program and options was reversed. As a result, I added thetspBefore
wrapper.The second change was to update the doc to include the
import
key, as it is necessary, since we can't use thedefault
export.Lastly, I updated the instructions to point to
ts-patch
instead of tts, due to it being effectively deprecated. That said, if anyone uses this same config with tts, using typescript <5, it will work for that as well.You're welcome to make any changes that you'd like! I just wanted the submission to be as complete as possible to save you some time.
Take care!