【发布时间】:2021-09-27 07:05:09
【问题描述】:
我正在使用带有 Ionic 的 4.3.5 版打字稿并且出现 ts(1378) 错误。
这里是 tsconfig:
{
"compilerOptions": {
"target": "es2017",
"lib": [
"dom",
"dom.iterable",
"esnext"
],
"sourceMap": true,
"noImplicitAny": true,
"allowJs": true,
"skipLibCheck": true,
"esModuleInterop": true,
"allowSyntheticDefaultImports": true,
"strict": true,
"forceConsistentCasingInFileNames": true,
"noFallthroughCasesInSwitch": true,
"module": "ESNext",
"moduleResolution": "node",
"resolveJsonModule": true,
"isolatedModules": true,
"noEmit": true,
"jsx": "react-jsx"
},
"include": [
"src"
],
"exclude": [
"node_modules",
"**/*.spec.ts"
]
}
还有我收到错误的代码:
import { Storage } from '@ionic/storage';
const store = new Storage();
await store.create();
export default store;
根据错误,我需要更改的只是目标为 >=es2017 和模块为 esnext 或系统,但我有,它仍然显示错误。
不知道是否相关,但你可以看到我的文件夹结构here。
提前致谢:)
【问题讨论】:
-
你确定一个 target >= es2017 就足够了吗?顶级等待是第 4 阶段的提案,因此甚至不是 es2020 的一部分。
-
我只是根据错误进行,但我只是尝试将目标设置为 ES2021 并且仍然有相同的错误
-
作为一种解决方法,您可以将代码包装在自动执行的
async function中。 -
@Thomas 是的,我做到了,只是想知道我是做错了什么还是错过了什么
-
@LoyalPotato - stackoverflow.com/a/69789625/4376643 - 这是关于让它与 typescript 和 ts-node 一起工作。 stefanjudis.com/today-i-learned/… - 是关于让它与 nodejs 一起使用。秘诀是让 TS 设置生成 ES 代码,而不是 CommonJS。所以它是两种参考的混合体。
标签: reactjs typescript ionic-framework async-await ecmascript-2017