You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Error creating Singleton instance of sap.ushell.Container in SAPUI5 1.120.12 with TypeScript #465
I am encountering an issue with SAPUI5 version 1.120.12 when trying to create a Singleton instance of sap.ushell.Container to get a Navigation Service for navigating to another SAPUI5 application using a semantic object and action.
Problem
The intended method call, as per the API documentation, should be:
What types do you use? @sapui5/types or one of the older artifacts (@sapui5/ts-types or @sapui5/ts-types-esm)?
@sapui5/types intentionally only exposes modules, no globals (as they are deprecated and will disappear in UI5 2.0). So the right way to refer to the container is to require it, either as a dependency in the sap.ui.define call of your module or via sap.ui.require("sap/ushell/Container") (a probing require call, the module must have been loaded already, e.g. by the containing FLP).
@codeworrior
I am using the new types "sapui5/types".
My expectation would be that I can import the "ushell.container" and then use it as a singleton/static class. That's what I did. I just adapted the coding to the API documentation therefore "sap.ushell.container".
@akudev The "sap.ushell.container" is still there and working correctly at runtime, so i do not think it is related to the open issue #347. However, the problem is with the linter, which incorrectly flag it as an error.
Is there already an internal solution for this, as the other issue has been pending for two years?
@akudev: thanks for fixing the old package names, I was too lazy to look them up. @Kasde96: the globals (as used in the API reference) can't and should not work in TypeScript (when using @sapui5/types), as explained above. If the module import also doesn't work, then @akudev is right and this is the same issue as in #347.
This problem has been fixed in SAPUI5 version 1.121 and later (hint to @akudev: internal change 6026907 in ushell).
I checked with the current types and the following works without linter errors:
If a downport is not possible, the following might be a workaround in 1.120 (I did not test it, just sketched the idea- and it needs to be removed in 1.121ff):
// in 1.120, the export of sap/ushell/Container is still a classimportContainerClassfrom"sap/ushell/Container";// Container is typed as an instance of the class, using the export of the module at runtime constContainer:ContainerClass=(ContainerClassasunknown);// from here on it's the sameconstnavService=awaitContainer.getServiceAsync("Navigation");
Activity
codeworrior commentedon Jul 8, 2024
What types do you use? @sapui5/types or one of the older artifacts (@sapui5/ts-types or @sapui5/ts-types-esm)?
@sapui5/types intentionally only exposes modules, no globals (as they are deprecated and will disappear in UI5 2.0). So the right way to refer to the container is to require it, either as a dependency in the
sap.ui.definecall of your module or viasap.ui.require("sap/ushell/Container")(a probing require call, the module must have been loaded already, e.g. by the containing FLP).[Edit by akudev: corrected old package names]
akudev commentedon Jul 9, 2024
Might this be a duplicate of the old and still open issue #347 ?
Kasde96 commentedon Jul 10, 2024
@codeworrior
I am using the new types "sapui5/types".
My expectation would be that I can import the "ushell.container" and then use it as a singleton/static class. That's what I did. I just adapted the coding to the API documentation therefore "sap.ushell.container".
Here is my coding:
Kasde96 commentedon Jul 10, 2024
@akudev The "sap.ushell.container" is still there and working correctly at runtime, so i do not think it is related to the open issue #347. However, the problem is with the linter, which incorrectly flag it as an error.
Is there already an internal solution for this, as the other issue has been pending for two years?
codeworrior commentedon Jul 10, 2024
@akudev: thanks for fixing the old package names, I was too lazy to look them up.
@Kasde96: the globals (as used in the API reference) can't and should not work in TypeScript (when using @sapui5/types), as explained above. If the module import also doesn't work, then @akudev is right and this is the same issue as in #347.
This problem has been fixed in SAPUI5 version 1.121 and later (hint to @akudev: internal change 6026907 in ushell).
I checked with the current types and the following works without linter errors:
@aaronbruchsap any chance to downport your fix to 1.120 as this is the LTS version?
codeworrior commentedon Jul 10, 2024
If a downport is not possible, the following might be a workaround in 1.120 (I did not test it, just sketched the idea- and it needs to be removed in 1.121ff):
Kasde96 commentedon Jul 10, 2024
@codeworrior Thanks for the workaround, the linter no longer shows errors.

The only thing i get now is this error in the vscode.
But that doesn't mind.
codeworrior commentedon Jul 10, 2024
Does
help?
Kasde96 commentedon Jul 10, 2024
Works perfectly, thank you.