自从 Angular 16 更新到 17 以来,我遇到了“openui5”的 TypeScript 编译错误

问题描述 投票:0回答:1

在 Angular16 中一切正常。我的开发依赖项中有

"@types/openui5" : "1.40.4"
。在
tsconfig.json
中有以下配置:

{
  "compilerOptions": {
    "downlevelIteration": true,
    "sourceMap": true,
    "declaration": false,
    "moduleResolution": "node",
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "target": "ES2022",
    "typeRoots": [
      "node_modules/@types"
    ],
    "lib": [
      "es2016",
      "dom"
    ],
    "outDir": "../out-tsc/app",
    "module": "ES2022",
    "baseUrl": "",
    "types": [
      "openui5"
    ],
     .
     .
  }
}

我收到错误:

Error: error TS2688: Cannot find type definition file for 'openui5'.
  The file is in the program because:
    Entry point of type library 'openui5' specified in compilerOptions

以及许多

doesn't exist
错误,例如:

error TS2339: Property 'getCore' does not exist on type 'typeof ui'.

55       sap.ui.getCore().getConfiguration().setLanguage(this.getSapLanguage());
                ~~~~~~~

no exported
错误,例如:

error TS2694: Namespace 'sap.ui' has no exported member 'base'.

1246         static getMetadata(): sap.ui.base.Metadata;
                                          ~~~~

更新到需要 Typescript 5.2 或更高版本的 Angular17 后,我收到此错误。在 Angular16 中配置了 Typescript 4.9。

这里出了什么问题?

angular typescript sapui5 angular17
1个回答
0
投票

我明白了。根本原因是 TS 5.1 中的更改:https://www.typescriptlang.org/docs/handbook/release-notes/typescript-5-1.html#typeroots-are-consulted-in-module-resolution

所以我必须删除

typeRoots
compilerOptions
中的
tsconfig.json
部分,一切又恢复正常了。

© www.soinside.com 2019 - 2024. All rights reserved.