Answer the question
In order to leave comments, you need to log in
Why can't use async/await in TypeScript?
I write in typescript using the koa framework. tsconfig.json is like this:
{
"compilerOptions": {
"module": "commonjs",
"target": "es6",
"noImplicitAny": false,
"sourceMap": false,
"typeRoots": [
"../node_modules/@types"
]
}
}
const koa = require('koa'),
app = new koa();
app.use(async (ctx, next) => {
const start: any = new Date();
await next();
const ms: any = 10 - start;
console.log(`${ctx.method} ${ctx.url} - ${ms}ms`);
});
app.use(ctx => {
ctx.body = 'kek';
console.log('start');
});
app.listen(3000);
error TS1311: Async functions are only available when targeting ECMAScript 2015 or higher.
Answer the question
In order to leave comments, you need to log in
TypeScript has supported async/await since version 2.1. And even when it compiles to ES3. Most likely, you do not have 2.1
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question