2016-06-08 37 views
9

mojego kodu testu jest jak następuje:maszynopis dekorator metoda nie działa

function test(target: Object, propertyKey: string, descriptor: TypedPropertyDescriptor<any>) { 
    return descriptor; 
} 

class Test { 
    @test 
    hello() { 
    } 
} 

ale kompilator dać mi błąd

Error:(33, 5) TS1241: Unable to resolve signature of method decorator when called as an expression. Supplied parameters do not match any signature of call target.

już określone: ​​ --experimentalDecorators --emitDecoratorMetadata

+0

to działa na mnie. z którą wersją maszynopisu się kompilujesz? – iberbeu

+0

tsc test.ts --experimentalDecorators --emitDecoratorMetadata – Jeff

+0

@iberbeu tsc --version Wersja 1.8.10 – Jeff

Odpowiedz

8

Wygląda na to, że TypeScript oczekuje, że typem zwrotnym funkcji dekoratora będzie "any" lub "v oid ". Więc w poniższym przykładzie, jeśli dodamy : any do końca, to skończy się działać.

function test(target: Object, 
       propertyKey: string, 
       descriptor: TypedPropertyDescriptor<any>): any { 
    return descriptor; 
} 
1

Zastosowanie --target ES5 --emitDecoratorMetadata --experimentalDecorators

lub kliknąć na poniższy config:

{ 
    "compilerOptions": { 
    "emitDecoratorMetadata": true, 
    "experimentalDecorators": true, 
    "target": "ES5" 
    } 
} 
Powiązane problemy