Skip to content

TypeScript 5.0 decorators don't work when noUnusedParameters is enabled and the context is unused #53208

@jlachniet

Description

@jlachniet

Bug Report

In the current version of TypeScript, decorators which don't use the context do not work properly when noUnusedParameters is enabled. If the decorator includes a context parameter, then the compiler reports an error on the unused parameter. If the decorator does not include the context parameter, than the decorator cannot be used, as the decorator is called with one too many arguments.

🔎 Search Terms

decorator, decorators

🕗 Version & Regression Information

This changed between versions 4.9 and 5.0

⏯ Playground Link

Playground link with relevant code

💻 Code

function MyDecorator(target: new (...args: never) => unknown) {
    console.log(target);
}

@MyDecorator 
class MyClass {}

🙁 Actual behavior

Code compiles without errors.

🙂 Expected behavior

TypeScript throws the following error:

Unable to resolve signature of class decorator when called as an expression.
  The runtime will invoke the decorator with 2 arguments, but the decorator expects 1.

Metadata

Metadata

Assignees

Labels

BugA bug in TypeScriptFix AvailableA PR has been opened for this issue

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions