SAP / ui5-webcomponents

UI5 Web Components - the enterprise-flavored sugar on top of native APIs! Build SAP Fiori user interfaces with the technology of your choice.
https://sap.github.io/ui5-webcomponents/
Apache License 2.0
1.47k stars 254 forks source link

[Component Name]:i18nBundle Bug #7300

Closed 2028942481 closed 11 months ago

2028942481 commented 1 year ago

Describe the bug

Hello, we are using ui5 for front-end development. The previous version we used was:

"@ui5/webcomponents": "^1.7.1", "@ui5/webcomponents-react": "^0.28.0"

Now you want to upgrade to:

"@ui5/webcomponents": "^1.15.0", "@ui5/webcomponents-react": "^1.17.0".

However, when we upgraded the version to the target version, the following issue occurred. Since we're using the TS language, it has strong type checking, but the interface to i18nBundle has changed in the updated version. Here is some of the code:

const i18nBundle = useI18nBundle('test'); message = i18nBundle.getText("TEST");

When TS compiles we get the following error:

“Argument of type 'string' is not assignable to parameter of type 'I18nText'.”

After checking the code, we find that in the file i18nBundle.d.ts, the getText method first receives arguments of type I18nText, which should also accept arguments of type string, otherwise the previous TS code will not work after updating the UI5 version. Please help us fix it, thank you.

Isolated Example

No response

Reproduction steps

1. 2. 3. ...

Expected Behaviour

No response

Screenshots or Videos

Screenshot 2023-07-06 135719

UI5 Web Components for React Version

1.17.0

UI5 Web Components Version

1.15.0

Browser

Chrome, Edge, Firefox, Safari

Operating System

No response

Additional Context

No response

Relevant log output

No response

Declaration

MarcusNotheis commented 1 year ago

Hi @2028942481,

thanks for reporting. We used to have our own typing the I18nBundle, but since the UI5 Web Components migrated to TypeScript as well, we're now reusing their types, so this issue needs to fixed in the UI5 Web Components Repository. I'll forward this issue accordingly.


Hi colleagues,

the documentation says that the I18nBundle.getText method can be called with both the object containing the I18n-key and default translation as well as with a string. The currently used type prohibits that. I would recommend to change the following line to getText(textObj: I18nText | string, ...params: Array<number | string>): string {:

https://github.com/SAP/ui5-webcomponents/blob/63180588e66efee4a18ad488ddff5a964d716c3f/packages/base/src/i18nBundle.ts#L34