powertools-lambda-typescript icon indicating copy to clipboard operation
powertools-lambda-typescript copied to clipboard

Feature request: support for TypeScript non experimental decorators (Stage 3)

Open WtfJoke opened this issue 1 year ago • 3 comments

Use case

We use Tracers functionality to capture class methods using decorators as described in the docs.

Typescript 5.0+ has official (non experimental) support for decorators.
However as soon as we remove the tsconfig.json flag experimentalDecorators (or set it to false) we get compile errors:

 error TS1241: Unable to resolve signature of method decorator when called as an expression.
  The runtime will invoke the decorator with 2 arguments, but the decorator expects 3.

34     @tracer.captureMethod()
       ~~~~~~~~~~~~~~~~~~~~~~~

  node_modules/@aws-lambda-powertools/tracer/lib/esm/types/Tracer.d.ts:100:100
    100 type MethodDecorator<T extends AnyClass> = (target: InstanceType<T>, propertyKey: string | symbol, descriptor: TypedPropertyDescriptor<AnyClassMethod>) => void;
                                                                                                           ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    An argument for 'descriptor' was not provided.

Solution/User Experience

It would be great if we have support for non experimental decorators so we can remove outdated decorators functionality.

Alternative solutions

No response

Acknowledgment

Future readers

Please react with 👍 and your use case to help us understand customer demand.

WtfJoke avatar Sep 18 '24 16:09 WtfJoke

Hi @WtfJoke, thanks for opening the issue.

This has been on my radar for a while but you're the first one to request it.

Technically speaking the change is doable, but it would be a breaking change we can't do it without a major version bump. Besides the change itself and the version bump, releasing a new major version would require us a significant amount of work in documentation, outreach, and support that we are not yet ready to take on - at least not until the end of the year.

Something that I would like to explore is whether we can support both versions of the decorator at the same time, possibly using the typeVersions field and some runtime checks on the shape of the arguments.

From a first exploration that I did when TS switched implementation, for what this library is concerned only modify the signature of the decorator factory & function. We'll have to see if we can support both at runtime and selectively chose the types.

For future readers, if you also want this feature please leave 👍 on the original comment and/or leave a comment with your use case. Having this type of influence will help us reassess the priority as needed.

dreamorosi avatar Sep 18 '24 19:09 dreamorosi

releasing a new major version would require us a significant amount of work in documentation, outreach, and support that we are not yet ready to take on - at least not until the end of the year.

Yeah I was hoping/assuming that there is no need for a major version change in implementing this feature. Instead maybe introducing a new method and deprecate the old one (and remove the deprecated one in the next major release).

I can understand that the next major version will be not around any soon :D.

Something that I would like to explore is whether we can support both versions of the decorator at the same time, possibly using the typeVersions field and some runtime checks on the shape of the arguments.

From a first exploration that I did when TS switched implementation, for what this library is concerned only modify the signature of the decorator factory & function. We'll have to see if we can support both at runtime and selectively chose the types.

That sounds promising and would be great (and match my hopes from above 😄 )!

Thanks for replying so fast and share your insights @dreamorosi

WtfJoke avatar Sep 19 '24 10:09 WtfJoke

No problem, also added this to the v3 feature list discussion #2560

dreamorosi avatar Sep 19 '24 10:09 dreamorosi