Improve error message for decorator type mismatches
See original GitHub issueIn TS 1.5 this:
//Relation.ts
export function Relation(cls: any) {
return function () {
console.log(cls);
}
}
//Foo.ts
import {Relation} from "./Relation";
export class Foo {
@Relation(Foo)
info: string;
}
Compiles without error. In TS 1.6, it reports the error:
error TS1240: Unable to resolve signature of property decorator when called as an expression.
Supplied parameters do not match any signature of call target.
On the decorator call in Foo.ts
. This is a very cryptic message. What it wants you to do is change Relation.ts
to read like this:
export function Relation(cls: any): PropertyDecorator {
return function () {
console.log(cls);
}
}
or this:
export function Relation(cls: any) {
return function (target: Object, propertyKey: string | symbol) {
console.log(cls);
}
}
It would be very useful for the error message to indicate what exactly is wrong and how it could be fixed. Something akin to
error TS1240: Expression type is not assignable to decorator type [[PropertyDecorator]]. Ensure [[@Relation(Foo)]] has a type assignable to [[PropertyDecorator]].
would be more useful in actually understanding what’s wrong and why you need to change your code.
Issue Analytics
- State:
- Created 8 years ago
- Reactions:24
- Comments:7 (2 by maintainers)
Top Results From Across the Web
Class decorator type mismatch error - Stack Overflow
The type ClassDecorator is defined to be a function that takes one argument, you return a function that takes three arguments, ...
Read more >Impex Translator - PK conversion not happening, argument ...
I get this error when I use translator: java.lang.IllegalArgumentException: Argument mismatch trying to set value 'approved' for attribute ...
Read more >I get a message about data type mismatch - Microsoft Support
I get a message about data type mismatch ... This error indicates that Access cannot match an input value to the data type...
Read more >Type Errors - Pyre
This error usually means you are using a variable in a way that is incompatible with its structure, either as an argument to...
Read more >Settings Reference for Python - Visual Studio Code
Settings Reference for the Python extension in Visual Studio Code. ... in increasing level of information provided, are off , error , warn...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
This may be tangential, but I had a tough time finding a solution. I was able to create a class factory by casting the return function. Not sure if this is a valid design pattern, but I am using it for dependency injection similar to what is seen in Angular2.
Looks like a fair proposal. feel free to send a PR if you like.