Description
Typescript >= v5 now has proper decorators implemented, known as stage 3: https://devblogs.microsoft.com/typescript/announcing-typescript-5-0/#decorators.
This means that it is no longer necessary to do this in the tsconfig.json
file:
{
"compilerOptions": {
[
...
]
"experimentalDecorators": true,
"emitDecoratorMetadata": true,
[...]
}
However, in stage 3, the entire schema has changed on what is sent into the decorators, so it breaks the functionality of the library.
For example, in the returned function for the decorator factory on JsonProperty
, instead of return function (target: any, classPropertyName: string): void
the code to accept the decorator invocation is now return function <C, V>(target: undefined, context: ClassFieldDecoratorContext<C, V>): void
In the above mentioned change, target
is now always undefined and will never be sent in to represent the class itself, therefore we need to play with the context
metadata to send in the mapping data needed by the JsonObject
decorator instead of setting the prototype on the target
.
I have already figured out what needs to be changed and have prepared some code changes on my side, but I'm not sure how this impacts all major frameworks when you change it.
The major problem with this is that for all projects using Babel (and other transpilers) this kind of change will not work. All those transpilers will change all stage 3 decorators into stage 2 decorators behind the scenes and I haven't found anything on how to configure this to not happen.
So in this case, will it be better to support this by releasing the changes as a new major version from a separate branch just for that? Not sure...
I will fork the project and try to create a PR for you to see the changes, but I'm not sure what's the best way to go around this breaking change in TS.