Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/typescript/8.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/templates/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Typescript 台糖原';t让我使用await关键字编译,甚至认为函数I';m使用的是异步的_Typescript_Typescript3.0 - Fatal编程技术网

Typescript 台糖原';t让我使用await关键字编译,甚至认为函数I';m使用的是异步的

Typescript 台糖原';t让我使用await关键字编译,甚至认为函数I';m使用的是异步的,typescript,typescript3.0,Typescript,Typescript3.0,当我尝试编译时: const result = await asyncFunction(); 我得到了“'await'表达式只允许使用异步函数”错误,即使我使用的函数使用的是async关键字。当我使用多个不同的异步函数为其他函数工作时,我一直会遇到这个错误,所以我知道这是我做错的事情 我正在使用typescript 3.2.2,并编译到节点10.15.0,但也尝试从以下位置编译到11.6: wait运算符用于等待承诺。它只能在异步函数中使用 此代码有效: async function test

当我尝试编译时:

const result = await asyncFunction();
我得到了“'await'表达式只允许使用异步函数”错误,即使我使用的函数使用的是async关键字。当我使用多个不同的异步函数为其他函数工作时,我一直会遇到这个错误,所以我知道这是我做错的事情

我正在使用typescript 3.2.2,并编译到节点10.15.0,但也尝试从以下位置编译到11.6:

wait
运算符用于等待
承诺
。它只能在
异步函数中使用

此代码有效:

async function test() {
  const result = await asyncFunction();
}
从:

wait
运算符用于等待
承诺
。它只能在
异步函数中使用

此代码有效:

async function test() {
  const result = await asyncFunction();
}