Angular 10 和 ES2020 中的模块解析因可选链而失败

Jim*_*lor 6 typescript optional-chaining ecmascript-2020 angular10

刚刚从 9.0 更新到 Angular 10

在我的代码中每次使用 Optional Chaining ( https://www.typescriptlang.org/docs/handbook/release-notes/typescript-3-7.html#optional-chaining ) 现在都会导致以下错误的实例

ERROR in ./src/app/app.component.ts 39:18
Module parse failed: Unexpected token (39:18)
File was processed with these loaders:
 * ./node_modules/@ngtools/webpack/src/index.js
You may need an additional loader to handle the result of these loaders.
|         this.title = 'my-app';
|         const x = this.GetObject();
>         let y = x?.myvar;
|     }
Run Code Online (Sandbox Code Playgroud)

我确认此错误仅在按照我的 tsconfig.base.json 文件中的以下内容定位 es2020 时发生,但在定位 es2019 时没问题

"target": "es2020",  //If set to es2019 then all OK
"module": "es2020",
"lib": [
   "es2018",  //Error also occurs if this set to es2020
    "dom"
  ],
Run Code Online (Sandbox Code Playgroud)

我确认这个错误在新生成的 Angular 10 应用程序中发生,如下所示,然后将目标更改为 es2020(所以它不是我的代码!)Typescript 版本是 3.9.7

npm install -g @angular/cli
ng new my-app
Run Code Online (Sandbox Code Playgroud)

我还注意到,在 es2020 的发行说明中,“可选链”现在是一项新功能。这让我怀疑'Optional Chaining'的Typescript编译不知何故没有与新的es2020功能结合?

如何在 es2020 中使用可选链?

Jim*_*lor 3

在 Angular 10 中使用可选链接同时面向 es2020 将导致错误“模块解析失败:意外的令牌”

当前的解决方法是针对 es2019