question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Improve error message for decorator type mismatches

See original GitHub issue

In 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:open
  • Created 8 years ago
  • Reactions:24
  • Comments:7 (2 by maintainers)

github_iconTop GitHub Comments

6reactions
stewhoustoncommented, May 20, 2016

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.

return function(decoratedClass:any) {
    function wrapConstructor(app) {
        return new decoratedClass(app, ...providers);
    }

    wrapConstructor.prototype = decoratedClass.prototype;

    return <typeof decoratedClass> wrapConstructor;
}
3reactions
mhegazycommented, Sep 1, 2015

Looks like a fair proposal. feel free to send a PR if you like.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found