Microsoft/TypeScript

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

Open

#39.991 aberto em 11 de ago. de 2020

Ver no GitHub
 (5 comments) (1 reaction) (0 assignees)TypeScript (6.726 forks)batch import
BugDomain: Error MessagesEffort: ModerateHelp Wanted

Métricas do repositório

Stars
 (48.455 stars)
Métricas de merge de PR
 (Mesclagem média 6d 17h) (9 fundiu PRs em 30d)

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.

Guia do colaborador