Open
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.