Skip to content

[feature request] Better error messages for decorators (they are completely not understandable) #39991

Open
@trusktr

Description

@trusktr

Search Terms

"Unable to resolve signature of property decorator when called as an expression"

Suggestion

The error message I received was error TS1240: Unable to resolve signature of property decorator when called as an expression.

This leaves absolutely no clue what is wrong.

Examples

To fix the issue, I had to change the signature of one of my functions from

export function attribute(
	prototype: any
	propName: string,
	descriptor: PropertyDescriptor | undefined,
): any

to

export function attribute(
	prototype: any
	propName: string,
	descriptor?: PropertyDescriptor | undefined,
): any

The difference is subtle: the descriptor arg isn't always passed to a decorator (depends on whether it is used on a property or on an accessor or method).

It'd be better if the message said something like The 'descriptor' argument to a property decorator should not be required.

Similar for other cases that trigger the same unhelpful error message.

Checklist

My suggestion meets these guidelines:

  • This wouldn't be a breaking change in existing TypeScript/JavaScript code
  • This wouldn't change the runtime behavior of existing JavaScript code
  • This could be implemented without emitting different JS based on the types of the expressions
  • This isn't a runtime feature (e.g. library functionality, non-ECMAScript syntax with JavaScript output, etc.)
  • This feature would agree with the rest of TypeScript's Design Goals.

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugA bug in TypeScriptDomain: Error MessagesThe issue relates to error messagingEffort: ModerateRequires experience with the TypeScript codebase, but feasible. Harder than "Effort: Casual".Help WantedYou can do this

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions