2016-06-08 18 views
9

mio codice di prova è simile al seguente:metodo dattiloscritto decoratore non funziona

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

class Test { 
    @test 
    hello() { 
    } 
} 

ma il compilatore darmi errore

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.

ho già specificato: --experimentalDecorators --emitDecoratorMetadata

+0

funziona per me. con quale versione di dattiloscritto stai compilando? – iberbeu

+0

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

+0

@iberbeu tsc --version Versione 1.8.10 – Jeff

risposta

8

Sembra che TypeScript si aspetti che il tipo di ritorno della funzione decoratore sia "qualsiasi" o "v" OID'. Quindi nell'esempio qui sotto, se aggiungiamo : any alla fine, si finisce per funzionare.

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

Usa --target ES5 --emitDecoratorMetadata --experimentalDecorators

o utilizzare la seguente configurazione:

{ 
    "compilerOptions": { 
    "emitDecoratorMetadata": true, 
    "experimentalDecorators": true, 
    "target": "ES5" 
    } 
} 
Problemi correlati