Skip to content

Commit

Permalink
feat(ts-interface-generator): add types for event parameters and events
Browse files Browse the repository at this point in the history
Event parameters of controls etc. are now available as types named like
"<ControlName>$<EventName>EventParameters" and the events themselves as
"<ControlName>$<EventName>Event". The respective event-related methods
make use of these events, so for consumers there is now full type
support regarding the events of controls developed with this
interface-generator.

ONE CAVEAT:
The generated types make use of the fact that sap.ui.base.Event is a
class with generics since version 1.115 of the UI5 types. For use with
lower versions of the UI5 types, the generator can create a kind of shim
that makes the Event class generic. This happens automatically based on
the version of the UI5 types AT CONTROL DEVELOPMENT TIME (i.e. only when
the control developer uses a version of the UI5 types lower than 1.115).

If, however, the application developer USING the control uses a
different version of the UI5 types than the control developer, then the
following happens:
1.) App uses >=1.115, Control uses < 1.115: the shim is there but does
not hurt.
2.) App uses <1.115, Control uses >= 1.115: the shim is missing and the
generated *.gen.d.ts file is not valid in the context of the app's UI5
types. However, TypeScript simply makes the type "any", so there there
is no big problem on application side, only reduced type safety.
Furthermore, "skipLibCheck" needs to be set to "true", otherwise the
TypeScript compiler reports an error when checking the UI5 types and the
generated interface files.

Tested to work in TS 4.7 (at least) up to 5.1.

fix #399
  • Loading branch information
akudev committed Jun 22, 2023
1 parent 22a6ad7 commit 7bc07b5
Show file tree
Hide file tree
Showing 7 changed files with 1,915 additions and 1,357 deletions.
2 changes: 1 addition & 1 deletion packages/ts-interface-generator/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
"@types/hjson": "2.4.3",
"@types/jest": "29.2.3",
"@types/node": "16.11.12",
"@types/openui5": "1.108.0",
"@types/openui5": "1.115.1",
"@types/yargs": "17.0.24",
"@typescript-eslint/eslint-plugin": "5.59.5",
"@typescript-eslint/parser": "5.59.5",
Expand Down
Loading

0 comments on commit 7bc07b5

Please sign in to comment.