Microsoft/TypeScript

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

Open

#39,991 opened on Aug 11, 2020

View on GitHub
聽(5 comments)聽(1 reaction)聽(0 assignees)TypeScript聽(48,455 stars)聽(6,726 forks)batch import
BugDomain: Error MessagesEffort: ModerateHelp Wanted

Description

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.

Contributor guide

[feature request] Better error messages for decorators (they are completely not understandable) 路 Microsoft/TypeScript#39991 | Good First Issue