typescript - 与 ES2020 无关的可选链接错误
问题描述
我在项目中使用可选链接时遇到问题。当我使用类似的东西时:
this.props.someString?.toUpperCase()
它不会导致 VS Code 中的任何语法错误,但会导致运行时错误
Module parse failed: Unexpected token (33:38) You may need an appropriate loader to handle this file type.
之前在 StackOverflow 上关于此问题的两篇文章都只声明将 tsconfig 中的目标更改为 es2020 或 es2018。我已经尝试过了,但它不起作用。我不确定要发布有关我的环境的其他上下文。我没有使用 Babel,我的 TS 版本是 3.9.9^。
编辑:tsconfig
{
"compilerOptions": {
"target": "es2020",
"lib": [
"dom",
"dom.iterable",
"esnext"
],
"allowJs": true,
"skipLibCheck": true,
"esModuleInterop": true,
"allowSyntheticDefaultImports": true,
"strict": true,
"forceConsistentCasingInFileNames": true,
"module": "esnext",
"moduleResolution": "node",
"resolveJsonModule": true,
"isolatedModules": true,
"noEmit": true,
"jsx": "preserve",
"noImplicitAny": false
},
"include": [
"src"
]
}
解决方案
推荐阅读
- c++ - 从调用的可调用目标将 std::function 设置为 nullptr
- sql - Go 中数据库迁移的正确策略
- python - python中的csv到txt
- java - 我们可以依靠 maven 在运行时处理类加载问题吗?
- php - Content-Type 标头值
- json - Json Schema Validation:对子模式的依赖
- angular - Angular 6:使用 npm start 启动我的应用程序时出错
- batch-file - 如何为主机列表循环一组命令?
- c# - C# - WPF:循环浏览 PDF 文件并在浏览器控件中显示
- python - Pyinstaller 给出关于未声明编码的错误