Skip to content

Conversation

Copy link

Copilot AI commented Nov 11, 2025

TypeScript 5 uses the stage 3 decorator spec with a 2-parameter signature (target, context), while this library only supported the experimental 3-parameter signature (target, propertyKey, descriptor), causing TypeScript 5 users to see "Unable to resolve signature of method decorator" errors.

Changes

  • memoizeDecorator implementation: Migrated to stage 3 decorator signature accepting ClassMethodDecoratorContext, returns memoized function instead of mutating descriptor
  • tsconfig.json: Removed experimentalDecorators flag
  • readme.md: Updated to require TypeScript 5.0+, noted migration path (memoize@10 for experimental decorator users)

Example

import {memoizeDecorator} from 'memoize';

class Example {
  index = 0

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

Now works without --experimentalDecorators in TypeScript 5+.

Breaking

Requires TypeScript 5.0+. Users on older versions or needing experimental decorator support should use memoize@10.

Original prompt

This section details on the original issue you should resolve

<issue_title>TypeScript 5's decorators are not supported</issue_title>
<issue_description>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.</issue_description>

<agent_instructions>Drop support for experimental decorators, only support the modern version. Update the minimum TS, Node and Browser version supported for this</agent_instructions>

Comments on the Issue (you are @copilot in this section)

@fregante 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</comment_new>


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot AI self-assigned this Nov 11, 2025
Copilot AI changed the title [WIP] Fix decorator support for TypeScript 5 Support TypeScript 5 stage 3 decorators, drop experimental decorators Nov 11, 2025
Copilot finished work on behalf of fregante November 11, 2025 09:19
Copilot AI requested a review from fregante November 11, 2025 09:19
@fregante fregante marked this pull request as ready for review November 11, 2025 09:42
@fregante fregante changed the title Support TypeScript 5 stage 3 decorators, drop experimental decorators Add support for non-experimental decorators Nov 11, 2025
Copy link
Collaborator

@fregante fregante left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems right but I'm not fully familiar with the decorators

@sindresorhus
Copy link
Owner

This is a welcome change, but it's breaking, and I don't plan any major version for a while, so this will need to stay open.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

TypeScript 5's decorators are not supported

3 participants