ui5-typescript
ui5-typescript copied to clipboard
tsc gives 'Duplicate identifier' error messages (@openui5/[email protected])
When running tsc
on an empty JavaScript file it gives the following error messages:
$ ./node_modules/typescript/bin/tsc
node_modules/@openui5/ts-types/types/sap.m.d.ts:301:15 - error TS2300: Duplicate identifier 'MessageBox'.
301 namespace MessageBox {
~~~~~~~~~~
node_modules/@openui5/ts-types/types/sap.m.d.ts:24179:15 - error TS2300: Duplicate identifier 'MessageBox'.
24179 interface MessageBox {
~~~~~~~~~~
node_modules/@openui5/ts-types/types/sap.m.d.ts:24868:11 - error TS2300: Duplicate identifier 'MessageBox'.
24868 const MessageBox: MessageBox;
~~~~~~~~~~
node_modules/@openui5/ts-types/types/sap.ui.commons.d.ts:3401:17 - error TS2300: Duplicate identifier 'MessageBox'.
3401 namespace MessageBox {
~~~~~~~~~~
node_modules/@openui5/ts-types/types/sap.ui.commons.d.ts:6401:17 - error TS2300: Duplicate identifier 'MessageBox'.
6401 interface MessageBox {
~~~~~~~~~~
node_modules/@openui5/ts-types/types/sap.ui.commons.d.ts:6526:13 - error TS2300: Duplicate identifier 'MessageBox'.
6526 const MessageBox: MessageBox;
~~~~~~~~~~
node_modules/@openui5/ts-types/types/sap.ui.core.d.ts:37617:19 - error TS2300: Duplicate identifier 'odata4analytics'.
37617 namespace odata4analytics {
~~~~~~~~~~~~~~~
node_modules/@openui5/ts-types/types/sap.ui.core.d.ts:39118:19 - error TS2300: Duplicate identifier 'odata4analytics'.
39118 interface odata4analytics {
~~~~~~~~~~~~~~~
node_modules/@openui5/ts-types/types/sap.ui.core.d.ts:39133:15 - error TS2300: Duplicate identifier 'odata4analytics'.
39133 const odata4analytics: odata4analytics;
~~~~~~~~~~~~~~~
node_modules/@openui5/ts-types/types/sap.ui.core.d.ts:58425:15 - error TS2300: Duplicate identifier 'Device'.
58425 namespace Device {
~~~~~~
node_modules/@openui5/ts-types/types/sap.ui.core.d.ts:59682:19 - error TS2300: Duplicate identifier 'dataTableUtils'.
59682 namespace dataTableUtils {
~~~~~~~~~~~~~~
node_modules/@openui5/ts-types/types/sap.ui.core.d.ts:59750:19 - error TS2300: Duplicate identifier 'dataTableUtils'.
59750 interface dataTableUtils {
~~~~~~~~~~~~~~
node_modules/@openui5/ts-types/types/sap.ui.core.d.ts:59826:15 - error TS2300: Duplicate identifier 'dataTableUtils'.
59826 const dataTableUtils: dataTableUtils;
~~~~~~~~~~~~~~
node_modules/@openui5/ts-types/types/sap.ui.core.d.ts:63827:15 - error TS2300: Duplicate identifier 'Device'.
63827 interface Device {}
~~~~~~
node_modules/@openui5/ts-types/types/sap.ui.core.d.ts:63828:11 - error TS2300: Duplicate identifier 'Device'.
63828 const Device: Device;
~~~~~~
Found 15 errors.
$ cat tsconfig.json
{
"compilerOptions": {
"incremental": true,
"noImplicitAny": false,
"noImplicitReturns": true,
"noImplicitThis": true,
"strictBindCallApply": true,
"strictFunctionTypes": true,
"strictPropertyInitialization": false,
"strictNullChecks": false,
"allowJs": true,
"checkJs": true,
"module": "ESNext",
"target": "ES2020",
"types": ["@openui5/ts-types", "@types/qunit", "@types/jquery"],
"noEmit": true,
"noFallthroughCasesInSwitch": true,
"allowUnreachableCode": false,
"allowUnusedLabels": false,
"lib": ["dom","es7"]
},
"include": [
"./empty.js"
]
}
$ npm list
[email protected] /Users/myuser/Documents/my_fiori
├── @openui5/[email protected]
├─┬ @types/[email protected]
│ └── @types/[email protected]
├── @types/[email protected]
└── [email protected]
Sorry for the delay (vacation time...). Our focus is on the "ts-types-esm" flavor of the type definitions right now, not the "ts-types" definitions which still define all the globals ("sap.m.Button" etc.) which we don't recommend to use anymore. Those "globals" definitions are mostly for code completion support in legacy projects. This doesn't mean we won't handle this issue report, but it is not a top priority right now. Thanks for the reminder, nevertheless. We have internally set up an ignorelist with these errors and put checks in place to prevent the introduction of new issues. So at least they shouldn't get more.
Using skipLibChecks
tsc compiler option may enable to you ignore all these issues at the consumer side
- https://www.typescriptlang.org/tsconfig#skipLibCheck
skipLibChecks: true
does suppress the error messages, however calling e.g. sap.m.MessageBox.error()
does not work because Typescript does not recognize error
in MessageBox
. Any updates on this? @akudev
these errors too:
node_modules/@sapui5/ts-types/types/sap.fe.navigation.d.ts:271:28 - error TS2702: 'JQuery' only refers to a type, but is being used as a namespace here.
271 parseNavigation(): JQuery.Promise<any, any, any>;
~~~~~~
node_modules/@sapui5/ts-types/types/sap.fe.navigation.d.ts:338:12 - error TS2702: 'JQuery' only refers to a type, but is being used as a namespace here.
338 ): JQuery.Promise<any, any, any>;
~~~~~~
node_modules/@sapui5/ts-types/types/sap.fe.test.d.ts:3092:13 - error TS2417: Class static side 'typeof ListReport' incorrectly extends base class static side 'typeof TemplatePage'.
Types of property 'actions' are incompatible.
Type 'actions' is missing the following properties from type 'actions': onActionDialog, onConfirmationDialog, onCreateDialog, onDialog, and 3 more.
3092 class ListReport extends sap.fe.test.TemplatePage {
~~~~~~~~~~
node_modules/@sapui5/ts-types/types/sap.fe.test.d.ts:3133:13 - error TS2417: Class static side 'typeof ObjectPage' incorrectly extends base class static side 'typeof TemplatePage'.
Types of property 'actions' are incompatible.
Type 'actions' is missing the following properties from type 'actions': onActionDialog, onConfirmationDialog, onCreateDialog, onDialog, and 3 more.
3133 class ObjectPage extends sap.fe.test.TemplatePage {
~~~~~~~~~~
To not leave these recent comments unanswered: as stated above, the "ts-types" with globals are not in focus anymore. This doesn't mean they'll never get improved, but the more important thing for us is getting the ESM types to production quality, sorry.
fair enough, i use the esm types where i can but in this case i need the old global types for a script i'm injecting onto a page that has window.sap
in it. more specifically, i'm making a playwright selector engine for ui5 - https://github.com/DetachHead/playwright-ui5/blob/0dc3c2db69dc6550ab173ba0de24bb976837cbf6/src/browser/main.ts#L28
if anybody knows of a way to do this with the esm types that would be nice
Hi @DetachHead ,
together with @akudev, we suggest the following and recommend the ESM type defs 😉 :
import type { registry } from 'sap/ui/core/Element'
// @ts-ignore
const ElementRegistry: registry = window.sap.ui.core.Element.registry
[...]
const controls = ElementRegistry.filter((element) => {
There is one caveat, starting with the UI5 type definitions 1.115.0
we reworked the types to better match the runtime code and therefore it will look like this then:
import type UI5Element from 'sap/ui/core/Element'
// @ts-ignore
const ElementRegistry: typeof UI5Element.registry = window.sap.ui.core.Element.registry
Would this be something you can live with?
(or define sap.ui.core.Element locally as custom type which happens to have the same "registry" as Element - this avoids the @ts-ignore)
Would this be something you can live with?
i wanted to avoid this kind of boilerplate though but i guess it's not that big of a deal for my use case where i'm only using one thing from the sap
namespace. thanks
@petermuessig i tried this on the latest version (1.120.1) but 'sap/ui/core/Element'
doesn't seem to be exported anymore?
import type { registry } from 'sap/ui/core/Element'
Cannot find module 'sap/ui/core/Element' or its corresponding type declarations.
@DetachHead Umm... that's one of the most important modules in UI5, I'm pretty sure it is still declared. Make sure the types are loaded.
oops i still was actually still using the global @sapui5/ts-types
package, my bad