在 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。
这里出了什么问题?
我明白了。根本原因是 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
部分,一切又恢复正常了。