仅当'module'选项设置为'esnext'时才允许使用顶级'await'表达式

我正在执行 Stripes 集成步骤,但遇到了在步骤 2.1 中发现的代码错误(https://stripe.com/docs/connect/collect-then-transfer-guide#create-an-account-link)

我该如何解决这个错误?

代码:

const stripe = require('stripe')('someID');
const account = await stripe.accounts.create({
  type: 'express',
});

错误:

仅当 'module' 选项设置为 'esnext' 或 'system',并且 'target' 选项设置为 'es2017' 或更高版本时,才允许使用顶级 'await' 表达式。 ts(1378)

回答

您可以将 const 帐户的代码包装在异步函数中,因为您的目标选项不支持顶级等待。

 const account = async () => {
        await stripe.accounts.create({
          type: "express",
  });
};

这取决于您的代码是要返回某些内容还是要在 await 之后执行其他一些任务。

如果你想使用顶级等待,更多关于使用顶级等待是在/sf/answers/3961327331/


以上是仅当'module'选项设置为'esnext'时才允许使用顶级'await'表达式的全部内容。
THE END
分享
二维码
< <上一篇
下一篇>>