2017-01-25 6 views
0

필자는 typescript와 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' ] 

만 두 개의 인수 그리고 나는이 간단한 코드를 시도했다. I는 타이프 운동장에서 이것을 실행할 경우

그러나,이 결과를 가지고

ARRA [0]과 배열 [2] 객체 및 배열 [1] 문자열이다
Array[3] 

.

어떻게 가능합니까? 또한 실험 장식자를 사용하여 타이프 스크립트를 어떻게 적절하게 컴파일해야합니까?

내 생각에 ...

답변

0

해결되었습니다. https://www.typescriptlang.org/docs/handbook/compiler-options.html에 따르면 기본 대상은 ES3입니다.

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

감사합니다 : ES5에 대한 목표를 설정

문제를 해결합니다.

관련 문제