Skip to content
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

TypeScript 5's decorators are not supported #102

Open
jwbth opened this issue Aug 12, 2024 · 1 comment
Open

TypeScript 5's decorators are not supported #102

jwbth opened this issue Aug 12, 2024 · 1 comment

Comments

@jwbth
Copy link

jwbth commented Aug 12, 2024

The example from the docs:

import {memoizeDecorator} from 'memoize';

class Example {
	index = 0

	@memoizeDecorator()
	counter() {
		return ++this.index;
	}
}

returns the following error in TypeScript 5:

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. ts(1241)
index.d.ts(109, 183): An argument for 'descriptor' was not provided.

The cause of this issue, I assume, is that the library only supports the stage 2 implementation of decorators. TypeScript 5 supports stage 3 decorator implementation without --experimentalDecorators, see https://devblogs.microsoft.com/typescript/announcing-typescript-5-0/#decorators.

@fregante
Copy link
Collaborator

If we were to support both, testing them would be an issue:

  • either run a second test file with --experimentalDecorators enabled
  • or "manually polyfill" the previous version in the class constructor, rather than calling it as an actual decorator

Dropping support for the old one might be troublesome for people who are using --emitDecoratorMetadata, but I think it's not the end of the world, they can stay on memoize@10. I propose just dropping support.

The blog post shows how to type these decorators: https://devblogs.microsoft.com/typescript/announcing-typescript-5-0/#writing-well-typed-decorators

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants