TypeScript decorator reports "Unable to resolve signature of class decorator when called as an expression"

The compiler expects your decorator to either be void or return a value that is compatible with A. It sees that you return a (msg:any) => any but can not draw the conclusion that this function is compatible with A.

If you want to get rid of the error, you can cast the ff to any when you return it, or maybe even to typeof A to communicate the intention clearer:

function xxx(arg: string)
{
    function f(target)
    {
        function ff(msg: string)
        {
            return new target(arg + ":" + msg)
        }
        return <typeof A><any>ff
    }
    return f
}

That said, it's probably not a good idea to replace classes like this, you should at least maintain the constructor:

TypeScript documentation:

NOTE Should you chose to return a new constructor function, you must take care to maintain the original prototype. The logic that applies decorators at runtime will not do this for you.


This appears to be resolved by adding ES2016 or ES5 as the target in tsconfig.json

https://github.com/alsatian-test/alsatian/issues/344#issuecomment-290418311

Tags:

Typescript