2017-11-19 7 views
2

다음 예제가 컴파일되지 않는 이유는 무엇입니까? 기본적으로 비동기 iterable 클로저를 올바르게 선언하는 방법이 문제입니다.Typescript : Async * iterator 클로저가 컴파일되지 않음

class Test { 
    async foo() { 
    const c = async() => { 
    }; 
    await c(); 
    } 

    async * bar() { 
    const c = async *() => { 
    }; 
    yield * c(); 
    } 
} 

오류는 다음과 같습니다

...: error TS1109: Expression expected. 
...: error TS1005: ';' expected. 

내 tsconfig.json : 나는 다음에 예를 변경하는 경우

{ 
    "compilerOptions": { 
    "declaration": true, 
    "lib": [ 
     "es2017", 
     "dom", 
     "esnext.asynciterable" 
    ], 
    "module": "commonjs", 
    "target": "es2015", 
    "sourceMap": true, 
    "outDir": "out", 
    "experimentalDecorators": true, 
    "emitDecoratorMetadata": true, 
    }, 
    "include": [ 
     "src/**/*.ts" 
    ] 
} 

, 그것은 작동합니다. 화살표 구문 대신 함수를 사용합니다.

class Test { 
    async foo() { 
    const c = async() => { 
    }; 
    await c(); 
    } 

    async * bar() { 
    const c = async function *() { 
    }; 
    yield * c(); 
    } 
} 
+2

오류와 어떤 오류가 있습니까? – Carcigenicate

+0

tsconfig.json의 내용을 표시해 주시겠습니까? –

답변

2

Arrow function()=>{} 및 일반 기능은 여기 놀이에 몇 가지 차이점이있다. 예를 들어 화살표 함수에는 this 바인딩이 없습니다. 또한 생성자에 대한 문서에서 반복을 위해 this을 사용하므로 function 구문을 사용해야한다고 분명히 명시되어 있습니다.