2017-01-25 3 views
0

私はタイプスクリプトとES7でデコレータの詳細を読んできました。これは私がコンソールに得るものです2つの引数を欺くTypescriptデコレータ、これをコンパイルする方法?

function decorator(...args) { 
    console.log(args); 
} 

//@decorator 
class foo { 
    constructor() {} 

    @decorator 
    method() {} 
} 

let bar = new foo(); 
bar.method(); 

$ npm install -g [email protected] 
$ npm install -g @types/node 
$ tsc --experimentalDecorators file.ts 
$ node file.js 
[ foo { method: [Function] }, 'method' ] 

2つだけ引数と私はこの単純なコードを試してみました。 ARRA [0]、配列[2]オブジェクトと配列である

しかし、私はtypescriptです遊び場でこれを実行した場合、私はこの結果を有する

Array[3] 

[1]の文字列です。

これはどのように可能ですか?さらに、実験的なデコレータでtypescriptを正しくコンパイルするにはどうすればよいですか?

答えて

0

解決済み。 https://www.typescriptlang.org/docs/handbook/compiler-options.htmlによると、デフォルトのターゲットはES3です。 ES5にターゲットを設定する

は、問題を解決:

$ tsc --experimentalDecorators -t 'es5' t.ts && node t.js 
[ foo { method: [Function] }, 
    'method', 
    { value: [Function], 
    writable: true, 
    enumerable: true, 
    configurable: true } ] 

よろしく。

関連する問題