Why does the following example not compile? Basically, the question is how to properly declare a async iterable closure.
class Test {
async foo() {
const c = async () => {
};
await c();
}
async * bar() {
const c = async * () => {
};
yield * c();
}
}
The errors are:
...: error TS1109: Expression expected.
...: error TS1005: ';' expected.
My 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"
]
}
If I change the example to the following, it works. I use a function instead of arrow syntax:
class Test {
async foo() {
const c = async () => {
};
await c();
}
async * bar() {
const c = async function *() {
};
yield * c();
}
}