ui5-typescript icon indicating copy to clipboard operation
ui5-typescript copied to clipboard

tsc gives 'Duplicate identifier' error messages (@openui5/[email protected])

Open one-github opened this issue 3 years ago • 12 comments

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]


one-github avatar Aug 26 '21 07:08 one-github

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.

akudev avatar Sep 13 '21 15:09 akudev

Using skipLibChecks tsc compiler option may enable to you ignore all these issues at the consumer side

  • https://www.typescriptlang.org/tsconfig#skipLibCheck

bd82 avatar Oct 07 '21 11:10 bd82

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

yishn avatar Apr 25 '23 11:04 yishn

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 {
                 ~~~~~~~~~~

DetachHead avatar Apr 27 '23 06:04 DetachHead

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.

akudev avatar May 02 '23 06:05 akudev

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

DetachHead avatar May 02 '23 07:05 DetachHead

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?

petermuessig avatar May 25 '23 10:05 petermuessig

(or define sap.ui.core.Element locally as custom type which happens to have the same "registry" as Element - this avoids the @ts-ignore)

akudev avatar May 25 '23 10:05 akudev

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

DetachHead avatar May 26 '23 00:05 DetachHead

@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 avatar Nov 15 '23 12:11 DetachHead

@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. image

akudev avatar Nov 15 '23 13:11 akudev

oops i still was actually still using the global @sapui5/ts-types package, my bad

DetachHead avatar Nov 15 '23 13:11 DetachHead