@ui5/mcp-server 0.1.6 → 0.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (27) hide show
  1. package/CHANGELOG.md +40 -0
  2. package/README.md +3 -1
  3. package/lib/registerTools.d.ts +2 -0
  4. package/lib/registerTools.js +4 -0
  5. package/lib/registerTools.js.map +1 -1
  6. package/lib/tools/get_typescript_conversion_guidelines/index.d.ts +3 -0
  7. package/lib/tools/get_typescript_conversion_guidelines/index.js +29 -0
  8. package/lib/tools/get_typescript_conversion_guidelines/index.js.map +1 -0
  9. package/lib/tools/get_typescript_conversion_guidelines/typescriptConversionGuidelines.d.ts +1 -0
  10. package/lib/tools/get_typescript_conversion_guidelines/typescriptConversionGuidelines.js +66 -0
  11. package/lib/tools/get_typescript_conversion_guidelines/typescriptConversionGuidelines.js.map +1 -0
  12. package/lib/tools/run_manifest_validation/index.d.ts +3 -0
  13. package/lib/tools/run_manifest_validation/index.js +30 -0
  14. package/lib/tools/run_manifest_validation/index.js.map +1 -0
  15. package/lib/tools/run_manifest_validation/runValidation.d.ts +2 -0
  16. package/lib/tools/run_manifest_validation/runValidation.js +130 -0
  17. package/lib/tools/run_manifest_validation/runValidation.js.map +1 -0
  18. package/lib/tools/run_manifest_validation/schema.d.ts +28 -0
  19. package/lib/tools/run_manifest_validation/schema.js +27 -0
  20. package/lib/tools/run_manifest_validation/schema.js.map +1 -0
  21. package/lib/utils/ui5Manifest.d.ts +17 -0
  22. package/lib/utils/ui5Manifest.js +105 -5
  23. package/lib/utils/ui5Manifest.js.map +1 -1
  24. package/npm-shrinkwrap.json +595 -100
  25. package/package.json +17 -15
  26. package/resources/integration_cards_guidelines.md +1 -0
  27. package/resources/typescript_conversion_guidelines.md +990 -0
@@ -0,0 +1,990 @@
1
+ # UI5 TypeScript Conversion Guidelines
2
+
3
+ > *This document outlines how a UI5 (SAPUI5/OpenUI5) project can be converted to TypeScript. The first part explains how the setup of the project needs to be changed, the second part deals with converting the code itself.*
4
+
5
+
6
+ ## General Conversion Rules
7
+
8
+ ### Preserve ALL comments
9
+
10
+ You MUST preserve existing JSDoc, documentation and comments - never remove JSDoc or comments during the conversion.
11
+
12
+ Example input:
13
+
14
+ ```js
15
+ /**
16
+ * My cool controller, it does things.
17
+ */
18
+ return Controller.extend("com.myorg.myapp.controller.BaseController", {
19
+ /**
20
+ * Convenience method for accessing the component of the controller's view.
21
+ * @returns {sap.ui.core.Component} The component of the controller's view
22
+ */
23
+ getOwnerComponent: function () {
24
+ // comment
25
+ return Controller.prototype.getOwnerComponent.call(this);
26
+ },
27
+ ...
28
+ });
29
+ ```
30
+
31
+ Wrong output:
32
+
33
+ ```ts
34
+ export default class BaseController extends Controller {
35
+ public getOwnerComponent(): UIComponent {
36
+ return super.getOwnerComponent() as UIComponent;
37
+ }
38
+ }
39
+ ```
40
+
41
+ Correct output:
42
+
43
+ ```ts
44
+ /**
45
+ * My cool controller, it does things.
46
+ * @namespace com.myorg.myapp.controller
47
+ */
48
+ export default class BaseController extends Controller {
49
+ /**
50
+ * Convenience method for accessing the component of the controller's view.
51
+ * @returns {sap.ui.core.Component} The component of the controller's view
52
+ */
53
+ public getOwnerComponent(): UIComponent {
54
+ // comment
55
+ return super.getOwnerComponent() as UIComponent;
56
+ }
57
+ }
58
+ ```
59
+
60
+ ### Be diligent
61
+
62
+ Carefully respect all guidelines in this document (and adapt appropriately where required). Before each conversion step, consider all relevant details from this document.
63
+
64
+ ### Go step-by-step
65
+
66
+ You should convert the project step by step, starting with the TypeScript project setup and then the most central files on which other files depend, so those other files can use the typed version of those central files once they are converted as well. `"allowJs": true` in the `tsconfig.json`'s `compilerOptions` may be useful to run semi-converted projects if needed.
67
+
68
+ ### Avoid `any` type
69
+
70
+ Do not take shortcuts, but try to find the proper type or create an interface instead of `any`.
71
+
72
+ BAD:
73
+ ```ts
74
+ (this.getOwnerComponent() as any).getContentDensityClass();
75
+ ```
76
+
77
+ GOOD:
78
+ ```ts
79
+ (this.getOwnerComponent() as AppComponent).getContentDensityClass()
80
+ ```
81
+
82
+ ### Avoid `unknown` casts
83
+
84
+ Import and use actual UI5 control types instead (either the base class `sap/ui/core/Control` or more specific classes if needed to access the respective property). Inspect the XMLView to find out which control type you actually get when calling `this.byId(...)` in a controller!
85
+ Don't forget using the specific event types like e.g. `Route$PatternMatchedEvent` for routing events.
86
+
87
+ #### Casting Example
88
+
89
+ BAD:
90
+ ```ts
91
+ (this.byId("form") as unknown as {setVisible: (v: boolean) => void}).setVisible(false);
92
+ ```
93
+
94
+ GOOD:
95
+
96
+ ```ts
97
+ import SimpleForm from "sap/ui/layout/form/SimpleForm";
98
+ (this.byId("form") as SimpleForm).setVisible(false);
99
+ ```
100
+
101
+ ### Create shared type definitions
102
+
103
+ Many type definitions you create are useful in different files. Create those in a central location like a file in in `src/types/`.
104
+
105
+
106
+ ## Project Setup Conversion
107
+
108
+ ### 1. package.json
109
+ You must add the following dev dependencies in the package.json file (very important) if they are not already present:
110
+
111
+ {{dependencies}}
112
+
113
+ However, if a dependency is already present in package.json, do not increase the major version number of it.
114
+ Do not remove existing dependencies, you must only add new configuration. Install the dependencies early to verify the types are found.
115
+
116
+ **IMPORTANT**: In addition, you **MUST** also add the `@sapui5/types` (or `@openui5/types`) package in a version matching the UI5 project as dev dependency. Framework type and version can be found in ui5.yaml or using the `get_project_info` MCP tool.
117
+
118
+ In addition, if (and ONLY if) dependencies or their versions changed, ensure (or tell the user) to execute npm install / yarn install (whatever is used in the project) to get the changed dependencies in the project.
119
+
120
+ The `typescript-eslint` dependency is only relevant when the project already has an eslint setup (details are below).
121
+
122
+ Also add the `"ts-typecheck": "tsc --noEmit"` script to `package.json`, so you and the developer can easily check for TypeScript errors.
123
+
124
+ ### 2. tsconfig.json
125
+
126
+ Add a tsconfig.json file. Use the following sample as reference, but adapt to the needs of the current project, e.g. adapt the paths map:
127
+
128
+ ```json
129
+ {
130
+ "compilerOptions": {
131
+ "target": "es2023",
132
+ "module": "es2022",
133
+ "moduleResolution": "node",
134
+ "skipLibCheck": true,
135
+ "allowJs": true,
136
+ "strict": true,
137
+ "strictNullChecks": false,
138
+ "strictPropertyInitialization": false,
139
+ "outDir": "./dist",
140
+ "rootDir": "./webapp",
141
+ "types": ["@sapui5/types", "@types/jquery", "@types/qunit"],
142
+ "paths": {
143
+ "com/myorg/myapp/*": ["./webapp/*"],
144
+ "unit/*": ["./webapp/test/unit/*"],
145
+ "integration/*": ["./webapp/test/integration/*"]
146
+ }
147
+ },
148
+ "exclude": ["./webapp/test/e2e/**/*"],
149
+ "include": ["./webapp/**/*"]
150
+ }
151
+ ```
152
+
153
+ ### 3. ui5.yaml
154
+
155
+ Update the ui5.yaml file to use the `ui5-tooling-transpile-task` and `ui5-tooling-transpile-middleware` and ensure that at least the following config is present:
156
+
157
+ ```yaml
158
+ builder:
159
+ customTasks:
160
+ - name: ui5-tooling-transpile-task
161
+ afterTask: replaceVersion
162
+ server:
163
+ customMiddleware:
164
+ - name: ui5-tooling-transpile-middleware
165
+ afterMiddleware: compression
166
+ - name: ui5-middleware-livereload
167
+ afterMiddleware: compression
168
+ ```
169
+
170
+ Ensure that the generated ui5.yaml file is valid - avoid duplicate entries, each root configuration must only exist once.
171
+ If a configuration like `server` already exists, you must add to it instead of adding a second entry.
172
+
173
+ ### 4. Eslint configuration
174
+
175
+ Only when the project has eslint set up, enhance the eslint configuration with TypeScript-specific parts. If eslint is not set up with dependency in package.json and an eslint config, then do nothing.
176
+ A complete eslint v9 compatible `eslint.config.mjs` file could e.g. look like this, but the actual content depends on the specific project, so you MUST adapt it!
177
+
178
+ ```js
179
+ import eslint from "@eslint/js";
180
+ import globals from "globals";
181
+ import tseslint from "typescript-eslint";
182
+
183
+ export default tseslint.config(
184
+ eslint.configs.recommended,
185
+ ...tseslint.configs.recommended,
186
+ ...tseslint.configs.recommendedTypeChecked,
187
+ {
188
+ languageOptions: {
189
+ globals: {
190
+ ...globals.browser,
191
+ sap: "readonly"
192
+ },
193
+ ecmaVersion: 2023,
194
+ parserOptions: {
195
+ project: true,
196
+ tsconfigRootDir: import.meta.dirname
197
+ }
198
+ }
199
+ },
200
+ {
201
+ ignores: ["eslint.config.mjs"]
202
+ }
203
+ );
204
+ ```
205
+
206
+
207
+ ## Application Code Conversion
208
+
209
+ ### Step 1: Change proprietary UI5 class syntax to standard ES class syntax
210
+
211
+ Every UI5 class definitions (`SuperClass.extend(...)`) must be converted to a standard JavaScript `class`.
212
+ The properties in the UI5 class configuration object (second parameter of `extend`) become members of the standard JavaScript class.
213
+ It is important to annotate the class with the namespace in a JSDoc comment, so the back transformation can re-add it.
214
+ The namespace is the part of the full package+class name (first parameter of `extend`) that precedes the class name.
215
+
216
+ Before (example):
217
+
218
+ ```js
219
+ [... other code, e.g. loading the dependencies "App", "Controller" etc. ...]
220
+
221
+ var App = Controller.extend("ui5tssampleapp.controller.App", {
222
+ onInit: function _onInit() {
223
+ // apply content density mode to root view
224
+ this.getView().addStyleClass(this.getOwnerComponent().getContentDensityClass());
225
+ }
226
+ });
227
+ ```
228
+
229
+
230
+ After (example, do not use this code verbatim):
231
+
232
+ ```js
233
+ [... other code, e.g. loading the dependencies "App", "Controller" etc. ...]
234
+
235
+ /**
236
+ * @namespace ui5tssampleapp.controller
237
+ */
238
+ class App extends Controller {
239
+ public onInit() {
240
+ // apply content density mode to root view
241
+ this.getView().addStyleClass((this.getOwnerComponent()).getContentDensityClass());
242
+ };
243
+ };
244
+ ```
245
+
246
+
247
+ ### Step 2: Change to ECMAScript modules and imports
248
+
249
+ TypeScript UI5 apps must use modern ES modules and imports.
250
+ Hence, convert all UI5 module definition and dependency loading calls (`sap.ui.require(...)`, `sap.ui.define(...)`)
251
+ to ES modules with imports (and in case of `sap.ui.define` a module export).
252
+
253
+ In the above example, this looks as follows.
254
+
255
+ Before:
256
+
257
+ ```js
258
+ sap.ui.define(["sap/ui/core/mvc/Controller"], function (Controller) {
259
+ /**
260
+ * @namespace ui5tssampleapp.controller
261
+ */
262
+ class App extends Controller {
263
+ ... // as above
264
+ };
265
+
266
+ return App;
267
+ });
268
+ ```
269
+
270
+ After:
271
+
272
+ ```js
273
+ import Controller from "sap/ui/core/mvc/Controller";
274
+
275
+ /**
276
+ * @namespace ui5tssampleapp.controller
277
+ */
278
+ export default class App extends Controller {
279
+ ... // as above
280
+ };
281
+ ```
282
+
283
+ `sap.ui.require` shall be converted to just the imports and no export.
284
+ Avoid name clashes for the imported modules.
285
+
286
+ > Hint: importing `sap/ui/core/Core` does not provide the class (like for most other UI5 modules), but the singleton instance of the UI5 Core. So the imported module can be used directly for methods like `byId(...)` instead of calls to `sap.ui.getCore()` which return the singleton in JavaScript.
287
+
288
+ When `sap.ui.require` is used dynamically, e.g. `sap.ui.require(["sap/m/MessageBox"], function(MessageBox) { ... })` inside a method body, then convert this to a dynamic import like `import("sap/m/MessageBox").then((MessageBox) => { ... })`.
289
+
290
+ ### Step 3: Standard TypeScript Code Adaptations
291
+
292
+ Apply your general knowledge about converting JavaScript code to TypeScript. In particular:
293
+
294
+ - Add type information to method parameters and variables where needed.
295
+ - Add missing private member class variables (with type information) to the beginning of the class definition. (In JavaScript they are often created later on-the-fly during the lifetime of a class instance.)
296
+ - Convert conventional `function`s to arrow functions when `someFunction.bind(...)` is used because TypeScript does not seem to propagate the type of the bound "this" context into the function body.
297
+ - Define further types and structures needed within the code, if applicable.
298
+
299
+ > IMPORTANT: whenever you use a UI5 type, e.g. for annotating a variable or method parameter/returntype, do NOT use the UI5 type with its global namespace (like `sap.m.Button` or `sap.ui.core.Popup`)! Instead, import this UI5 type from the respective module (like `sap/m/Button` or `sap/ui/core/Popup` - add an import if needed) and use the imported module.
300
+
301
+ Example:
302
+
303
+ Wrong:
304
+ ```ts
305
+ const b: sap.m.Button;
306
+ function getPopup(): sap.ui.core.Popup { ... }
307
+ ```
308
+
309
+ Correct:
310
+ ```ts
311
+ import Button from "sap/m/Button";
312
+ import Popup from "sap/ui/core/Popup";
313
+
314
+ const b: Button;
315
+ function getPopup(): Popup { ... }
316
+ ```
317
+
318
+ Hint: use the actual UI5 control events, not browser events like `Event` or `MouseEvent`, in event handlers of UI5 controls. UI5 events are different. E.g. use the `Button$PressEvent` and `Button$PressEventParameters` from the `sap/m/Button` module when the `press` event of the `sap/m/Button` is handled.
319
+
320
+ > Note: for any event XYZ of a UI5 control ABC, types like `ABC$XYZEvent` and `ABC$XYZEventParameters` are available!
321
+
322
+
323
+ Example:
324
+
325
+ Before:
326
+
327
+ ```js
328
+ sap.ui.define(["./BaseController"], function (BaseController) {
329
+ return BaseController.extend("my.app.controller.Main", {
330
+ onPress: function(oEvent) {
331
+ const button = oEvent.getSource();
332
+ },
333
+
334
+ onSelectionChange: function(oEvent) {
335
+ const items = oEvent.getParameter("selectedItems");
336
+ }
337
+ });
338
+ });
339
+ ```
340
+
341
+ After:
342
+
343
+ ```ts
344
+ import BaseController from "./BaseController";
345
+ import Button from "sap/m/Button";
346
+ import {Button$PressEvent} from "sap/m/Button";
347
+ import {Table$RowSelectionChangeEvent} from "sap/ui/table/Table";
348
+
349
+ export default class Main extends BaseController {
350
+ onPress(oEvent: Button$PressEvent): void {
351
+ const button = oEvent.getSource() as Button;
352
+ }
353
+
354
+ onRowSelectionChange(oEvent: Table$RowSelectionChangeEvent): void {
355
+ const selectedContext = oEvent.getParameter("rowContext");
356
+ }
357
+ }
358
+ ```
359
+
360
+
361
+ Hint: use the most specific type which does provide all needed properties. Examples:
362
+ - Use specific types like `KeyboardEvent` or `MouseEvent`, not just `Event` for browser events.
363
+ - Use the `Button$PressEvent` from the `sap/m/Button` module, not the `sap/ui/base/Event`.
364
+ - The same is valid for all types, not only events.
365
+
366
+
367
+ ### Step 4: Casts for Return Values of Generic Methods
368
+
369
+ Generic getter methods like `document.getElementById(...)` or `someUI5Control.getModel()` or inside a controller `this.byId()` return the super-type of all possible types (in the examples `HTMLElement` and `sap.ui.model.Model` and `sap.ui.core.Element`) although in practice it will usually be a specific sub-type (e.g. an `HTMLAnchorElement` or a `sap.ui.model.odata.v4.ODataModel` or a `sap.m.Input`).
370
+
371
+ In many cases you will have to cast the return value to the specific type to use it. The actual type can usually be derived from the context. If not, rather avoid the cast than guessing a wrong one. Also, do not cast to a superclass like `sap.ui.model.Model` when this is anyway the returned type.
372
+
373
+ The same is valid for several UI5 methods, most prominently the following:
374
+ - core.byId() / view.byId()
375
+ - control.getBinding()
376
+ - ownerComponent.getModel()
377
+ - event.getSource()
378
+ - component.getRootControl()
379
+ - this.getOwnerComponent()
380
+
381
+ This cast will sometimes also require an additional module import to make the type (like `ODataModel` above) known.
382
+
383
+ In the app controller example above, this step would add an additional import of the app's component (called `AppComponent`), so within the `onInit` implementation the required typecast can be done. Without this typecast, the return type of `getOwnerComponent` would be a `sap.ui.core.Component`, which does not have the `getContentDensityClass` method defined in the app component.
384
+
385
+ Before:
386
+ ```js
387
+ import Controller from "sap/ui/core/mvc/Controller";
388
+
389
+ /**
390
+ * @namespace ui5tssampleapp.controller
391
+ */
392
+ export default class App extends Controller {
393
+
394
+ public onInit() {
395
+ // apply content density mode to root view
396
+ this.getView().addStyleClass(this.getOwnerComponent().getContentDensityClass());
397
+ };
398
+
399
+ };
400
+ ```
401
+
402
+ After:
403
+ ```ts
404
+ import Controller from "sap/ui/core/mvc/Controller";
405
+ import AppComponent from "../Component";
406
+
407
+ /**
408
+ * @namespace ui5tssampleapp.controller
409
+ */
410
+ export default class App extends Controller {
411
+
412
+ public onInit() : void {
413
+ // apply content density mode to root view
414
+ this.getView().addStyleClass((this.getOwnerComponent() as AppComponent).getContentDensityClass());
415
+ };
416
+
417
+ };
418
+ ```
419
+
420
+
421
+ (Note: the "void" definition of the method return type is not strictly demanded by TypeScript, but is beneficial e.g. depending on the linting settings.)
422
+
423
+
424
+ ### Step 5: Solving any Remaining Issues
425
+
426
+ At this point, the number of remaining TypeScript errors should be vastly reduced.
427
+ If you clearly recognize some, fix them, but in case of doubt mention the last remaining issues to the developer.
428
+
429
+
430
+ ## UI5 Control TypeScript Conversion Guidelines
431
+
432
+ > *This section covers the conversion of UI5 custom controls from JavaScript to TypeScript. This applies both to single custom controls within applications and to control libraries.*
433
+
434
+ Converting custom UI5 controls to TypeScript requires specific patterns in addition to the general TypeScript conversion (converting the proprietary UI5 class and syntax).
435
+
436
+ ### The Runtime-Generated Methods Problem (CRITICAL)
437
+
438
+ **This is the most important aspect to understand.**
439
+
440
+ UI5 generates getter/setter (and more) methods for all properties, aggregations, associations, and events at **runtime**. This means TypeScript cannot see these methods at development time, causing type errors.
441
+
442
+ #### The Problem
443
+
444
+ In a control with a `text` property defined in metadata:
445
+
446
+ ```typescript
447
+ static readonly metadata: MetadataOptions = {
448
+ properties: {
449
+ "text": "string"
450
+ }
451
+ };
452
+ ```
453
+
454
+ TypeScript will show errors when trying to use the generated methods:
455
+
456
+ ```typescript
457
+ rm.text(control.getText()); // ERROR: Property 'getText' does not exist on type 'MyControl'
458
+ ```
459
+
460
+ Additionally, TypeScript doesn't know the constructor signature structure for initializing controls:
461
+
462
+ ```typescript
463
+ new MyControl("myId", {text: "Hello"}); // TypeScript doesn't know about the settings object structure
464
+ ```
465
+
466
+ This affects:
467
+ - Property getters/setters: `getText()`, `setText()`, `bindText()`
468
+ - Aggregation methods: `addItem()`, `removeItem()`, `getItems()`, ...
469
+ - Association methods: `getLabel()`, `setLabel()`
470
+ - Event methods: `attachPress()`, `detachPress()`, `firePress()`
471
+ - Constructor settings object structure
472
+
473
+ #### The Solution: @ui5/ts-interface-generator
474
+
475
+ Install the interface generator tool as a dev dependency:
476
+
477
+ ```sh
478
+ npm install --save-dev @ui5/ts-interface-generator@{{ts-interface-generator-version}}
479
+ ```
480
+
481
+ To make subsequent development easier, add a script like this to `package.json`:
482
+
483
+ ```json
484
+ {
485
+ "scripts": {
486
+ "watch:controls": "npx @ui5/ts-interface-generator --watch"
487
+ }
488
+ }
489
+ ```
490
+
491
+ NOTE: the tsconfig file related to the controls must be in the same directory in which the interface generator is launched. If you launch it in the root of your project and the tsconfig covering the TypeScript controls is in a subdirectory or has a different name than `tsconfig.json`, then call it like ` npx @ui5/ts-interface-generator --watch --config path/to/tsconfig.json`.
492
+
493
+ After TypeScript conversion of all controls, run the generator once to generate the needed control interfaces:
494
+
495
+ ```bash
496
+ npm run watch:controls
497
+ ```
498
+
499
+ This generates a `*.gen.d.ts` file (e.g., `MyControl.gen.d.ts`) containing TypeScript interfaces with all the runtime-generated methods. TypeScript merges these interfaces with the control class.
500
+
501
+ These generated files should be committed to version control and never edited manually.
502
+
503
+ #### Required Constructor Signatures (CRITICAL MANUAL STEP)
504
+
505
+ After running the interface generator, you must manually copy the constructor signatures from the terminal output into the respective control class.
506
+
507
+ The generator outputs something like:
508
+
509
+ ```
510
+ ===== BEGIN =====
511
+ // The following three lines were generated and should remain as-is to make TypeScript aware of the constructor signatures
512
+ constructor(id?: string | $MyControlSettings);
513
+ constructor(id?: string, settings?: $MyControlSettings);
514
+ constructor(id?: string, settings?: $MyControlSettings) { super(id, settings); }
515
+ ===== END =====
516
+ ```
517
+
518
+ **Copy these lines into the beginning of the class body**, before the metadata definition:
519
+
520
+ ```typescript
521
+ export default class MyControl extends Control {
522
+ // The following three lines were generated and should remain as-is to make TypeScript aware of the constructor signatures
523
+ constructor(id?: string | $MyControlSettings);
524
+ constructor(id?: string, settings?: $MyControlSettings);
525
+ constructor(id?: string, settings?: $MyControlSettings) { super(id, settings); }
526
+
527
+ static readonly metadata: MetadataOptions = {
528
+ // ...
529
+ };
530
+ }
531
+ ```
532
+
533
+ ### Control Metadata Typing
534
+
535
+ The control metadata must be typed as `MetadataOptions`:
536
+
537
+ ```typescript
538
+ import type { MetadataOptions } from "sap/ui/core/Element";
539
+
540
+ export default class MyControl extends Control {
541
+ static readonly metadata: MetadataOptions = {
542
+ properties: {
543
+ "text": "string"
544
+ }
545
+ };
546
+ }
547
+ ```
548
+
549
+ **Important points:**
550
+ - Import `MetadataOptions` from `sap/ui/core/Element` for controls (or closest base class - also available for `sap/ui/core/Object`, `sap/ui/core/ManagedObject`, and `sap/ui/core/Component`)
551
+ - Use `import type` instead of `import` (design-time only, no runtime impact)
552
+ - `MetadataOptions` available since UI5 1.110; use `object` for earlier versions
553
+ - Typing prevents issues when inheriting from the control (inherited properties should not be repeated)
554
+
555
+ ### Namespace Annotation Required
556
+
557
+ The `@namespace` JSDoc annotation is **required** for the transformer to generate correct UI5 class names:
558
+
559
+ ```typescript
560
+ /**
561
+ * @namespace ui5.typescript.helloworld.control
562
+ */
563
+ export default class MyControl extends Control {
564
+ // ...
565
+ }
566
+ ```
567
+
568
+ ### Export Pattern
569
+
570
+ **Must use `export default` immediately when defining the class**, otherwise ts-interface-generator will fail:
571
+
572
+ ```typescript
573
+ // CORRECT:
574
+ export default class MyControl extends Control {
575
+ // ...
576
+ }
577
+
578
+ // WRONG - separate export:
579
+ class MyControl extends Control {
580
+ // ...
581
+ }
582
+ export default MyControl;
583
+ ```
584
+
585
+ ### Static Members for Metadata and Renderer
586
+
587
+ Both metadata and renderer are defined as `static` class members:
588
+
589
+ ```typescript
590
+ import RenderManager from "sap/ui/core/RenderManager";
591
+
592
+ export default class MyControl extends Control {
593
+ static readonly metadata: MetadataOptions = {
594
+ properties: {
595
+ "text": "string"
596
+ }
597
+ };
598
+
599
+ static renderer = {
600
+ apiVersion: 2,
601
+ render: function (rm: RenderManager, control: MyControl): void {
602
+ rm.openStart("div", control);
603
+ rm.openEnd();
604
+ rm.text(control.getText());
605
+ rm.close("div");
606
+ }
607
+ };
608
+ }
609
+ ```
610
+
611
+ The renderer can also be in a separate file (common in libraries) and should in this case stay separate when converting to TypeScript.
612
+
613
+ The following JavaScript code:
614
+
615
+ ```javascript
616
+ sap.ui.define([
617
+ "sap/ui/core/Control",
618
+ "./MyControlRenderer"
619
+ ], function (Control, MyControlRenderer) {
620
+ "use strict";
621
+
622
+ return Control.extend("com.myorg.myapp.control.MyControl", {
623
+ ...
624
+ renderer: MyControlRenderer,
625
+ ...
626
+ ```
627
+
628
+ is then converted to this TypeScript code:
629
+
630
+ ```typescript
631
+ import Control from "sap/ui/core/Control";
632
+ import type { MetadataOptions } from "sap/ui/core/Element";
633
+ import MyControlRenderer from "./MyControlRenderer";
634
+
635
+ /**
636
+ * @namespace com.myorg.myapp.control
637
+ */
638
+ export default class MyControl extends Control {
639
+ ...
640
+ static renderer = MyControlRenderer;
641
+ ...
642
+ ```
643
+
644
+ ### Complete Control Example
645
+
646
+ #### JavaScript (Before):
647
+
648
+ ```javascript
649
+ sap.ui.define([
650
+ "sap/ui/core/Control",
651
+ "sap/ui/core/RenderManager"
652
+ ], function (Control, RenderManager) {
653
+ "use strict";
654
+
655
+ var MyControl = Control.extend("ui5.typescript.helloworld.control.MyControl", {
656
+ metadata: {
657
+ properties: {
658
+ "text": "string"
659
+ },
660
+ events: {
661
+ "press": {}
662
+ }
663
+ },
664
+
665
+ renderer: function (rm, control) {
666
+ rm.openStart("div", control);
667
+ rm.openEnd();
668
+ rm.text(control.getText());
669
+ rm.close("div");
670
+ },
671
+
672
+ onclick: function() {
673
+ this.firePress();
674
+ }
675
+ });
676
+
677
+ return MyControl;
678
+ });
679
+ ```
680
+
681
+ #### TypeScript (After):
682
+
683
+ ```typescript
684
+ import Control from "sap/ui/core/Control";
685
+ import type { MetadataOptions } from "sap/ui/core/Element";
686
+ import RenderManager from "sap/ui/core/RenderManager";
687
+
688
+ /**
689
+ * @namespace ui5.typescript.helloworld.control
690
+ */
691
+ export default class MyControl extends Control {
692
+ // The following three lines were generated and should remain as-is to make TypeScript aware of the constructor signatures
693
+ constructor(id?: string | $MyControlSettings);
694
+ constructor(id?: string, settings?: $MyControlSettings);
695
+ constructor(id?: string, settings?: $MyControlSettings) { super(id, settings); }
696
+
697
+ static readonly metadata: MetadataOptions = {
698
+ properties: {
699
+ "text": "string"
700
+ },
701
+ events: {
702
+ "press": {}
703
+ }
704
+ };
705
+
706
+ static renderer = {
707
+ apiVersion: 2,
708
+ render: function (rm: RenderManager, control: MyControl): void {
709
+ rm.openStart("div", control);
710
+ rm.openEnd();
711
+ rm.text(control.getText());
712
+ rm.close("div");
713
+ }
714
+ };
715
+
716
+ onclick(): void {
717
+ this.firePress();
718
+ }
719
+ }
720
+ ```
721
+
722
+ ### Library-Specific Guidelines
723
+
724
+ When converting entire control libraries (not just single controls in apps), additional steps are required:
725
+
726
+ #### Library Module with Enums (CRITICAL to avoid XSS issues!)
727
+
728
+ In `library.ts`, enums must be attached to the global library object for UI5 runtime compatibility:
729
+
730
+ ```typescript
731
+ import ObjectPath from "sap/base/util/ObjectPath";
732
+
733
+ // Define enum as TypeScript enum
734
+ export enum ExampleColor {
735
+ Red = "Red",
736
+ Green = "Green",
737
+ Blue = "Blue"
738
+ }
739
+
740
+ // CRITICAL: Attach to global library object
741
+ const thisLib = ObjectPath.get("com.myorg.myui5lib") as {[key: string]: unknown};
742
+ thisLib.ExampleColor = ExampleColor;
743
+ ```
744
+
745
+ **Why this is critical for every enum in the library:**
746
+ - Control properties reference types as global names: `type: "com.myorg.myui5lib.ExampleColor"`
747
+ - UI5 runtime needs to find the enum via this global path
748
+ - Without this, UI5 cannot validate the property type
749
+ - This breaks type checking and can create XSS vulnerabilities as unchecked content can be written to HTML unexpectedly
750
+
751
+
752
+ #### Path Mapping in tsconfig.json
753
+
754
+ For libraries, add path mappings for the library namespace:
755
+
756
+ ```json
757
+ {
758
+ "compilerOptions": {
759
+ "paths": {
760
+ "com/myorg/mylib/*": ["./src/*"]
761
+ }
762
+ }
763
+ }
764
+ ```
765
+
766
+ ### Control Conversion Checklist
767
+
768
+ When converting a control from JavaScript to TypeScript:
769
+
770
+ 1. Convert to ES6 class/module like regular UI5 modules
771
+ 2. Add `@namespace` JSDoc annotation
772
+ 3. Use `export default` **immediately** with class definition
773
+ 4. Type metadata as `MetadataOptions` (import from appropriate base class)
774
+ 5. Define metadata and renderer as `static` members
775
+ 6. Install and run `@ui5/ts-interface-generator`
776
+ 7. Copy constructor signatures from generator output into class
777
+ 8. If in a library: manually attach enums to global library object
778
+ 9. Preserve all JSDoc comments and documentation
779
+
780
+
781
+ ## Test Conversion
782
+
783
+ > *There are critical, non-obvious patterns for converting UI5 test code from JavaScript to TypeScript. Standard ES6 module/class conversions and renaming of files to `*.ts` also applies, like for regular application code and controls.*
784
+
785
+ NOTE: The test code file related changes below (especially those for OPA tests) always apply when converting the tests to TypeScript, but the test setup and running (like in `testsuite.qunit.ts`) may depend on how exactly the tests are set up in the project.
786
+
787
+ Test conversion should only happen once the rest of the application has been converted successfully.
788
+
789
+ ### Explicit QUnit Import Required
790
+
791
+ Unlike JavaScript where QUnit is often used as a global, TypeScript requires explicit import:
792
+
793
+ ```typescript
794
+ import QUnit from "sap/ui/thirdparty/qunit-2";
795
+ ```
796
+
797
+ ### Test Registration in testsuite.qunit.ts
798
+
799
+ The testsuite configuration uses plain `export default` (no sap.ui.define wrapper):
800
+
801
+ ```typescript
802
+ export default {
803
+ name: "Testsuite for the com/myorg/myapp app",
804
+ defaults: {
805
+ page: "ui5://test-resources/...",
806
+ loader: {
807
+ paths: {
808
+ "com/myorg/myapp": "../",
809
+ "integration": "./integration",
810
+ "unit": "./unit"
811
+ }
812
+ }
813
+ },
814
+ tests: {
815
+ "unit/unitTests": { title: "..." },
816
+ "integration/opaTests": { title: "..." }
817
+ }
818
+ };
819
+ ```
820
+
821
+ ### tsconfig.json Path Mappings for Tests
822
+
823
+ **Essential**: Add path mappings and QUnit types (like in this sample, but adapt to the specific app which is converted):
824
+
825
+ ```json
826
+ {
827
+ "compilerOptions": {
828
+ "types": ["@sapui5/types", "@types/qunit"],
829
+ "paths": {
830
+ "com/myorg/myapp/*": ["./webapp/*"],
831
+ "unit/*": ["./webapp/test/unit/*"],
832
+ "integration/*": ["./webapp/test/integration/*"]
833
+ }
834
+ }
835
+ }
836
+ ```
837
+
838
+ ### OPA Integration Tests - Fundamental Architecture Change
839
+
840
+ JavaScript Pattern (OLD) - NOT USED IN TYPESCRIPT:
841
+
842
+ ```javascript
843
+ sap.ui.define(["sap/ui/test/opaQunit", "./pages/App"], (opaTest) => {
844
+ opaTest("should add an item", (Given, When, Then) => {
845
+ Given.iStartMyApp();
846
+ When.onTheAppPage.iEnterText("test");
847
+ Then.onTheAppPage.iShouldSeeItem("test");
848
+ Then.iTeardownMyApp();
849
+ });
850
+ });
851
+ ```
852
+
853
+ TypeScript Pattern (NEW) - MUST BE USED:
854
+
855
+ ```typescript
856
+ import opaTest from "sap/ui/test/opaQunit";
857
+ import AppPage from "./pages/AppPage";
858
+ import QUnit from "sap/ui/thirdparty/qunit-2";
859
+
860
+ const onTheAppPage = new AppPage();
861
+
862
+ QUnit.module("Test Module");
863
+
864
+ opaTest("Should open dialog", function () {
865
+ onTheAppPage.iStartMyUIComponent({
866
+ componentConfig: { name: "ui5.typescript.helloworld" }
867
+ });
868
+
869
+ onTheAppPage.iPressButton();
870
+ onTheAppPage.iShouldSeeDialog();
871
+ onTheAppPage.iTeardownMyApp();
872
+ });
873
+ ```
874
+
875
+ Critical Rules:
876
+ 1. **NO Given/When/Then parameters** in the opaTest callback
877
+ 2. **Create page instances BEFORE tests**: `const onTheAppPage = new AppPage();`
878
+ 3. **Call all methods directly on the page instance** (arrangements, actions, assertions, cleanup)
879
+
880
+ ### OPA Page Objects - Class-Based Only
881
+
882
+ JavaScript uses createPageObjects() - DO NOT USE IN TYPESCRIPT
883
+
884
+ TypeScript uses classes extending Opa5:
885
+
886
+ ```typescript
887
+ import Opa5 from "sap/ui/test/Opa5";
888
+ import Press from "sap/ui/test/actions/Press";
889
+
890
+ const viewName = "ui5.typescript.helloworld.view.App";
891
+
892
+ export default class AppPage extends Opa5 {
893
+ iPressButton() {
894
+ return this.waitFor({
895
+ id: "myButton",
896
+ viewName,
897
+ actions: new Press(),
898
+ errorMessage: "Did not find button"
899
+ });
900
+ }
901
+
902
+ iShouldSeeDialog() {
903
+ return this.waitFor({
904
+ controlType: "sap.m.Dialog",
905
+ success: function () {
906
+ Opa5.assert.ok(true, "Dialog is open");
907
+ },
908
+ errorMessage: "Did not find dialog"
909
+ });
910
+ }
911
+ }
912
+ ```
913
+
914
+ Key Points:
915
+ - **NO createPageObjects()** - use ES6 class extending Opa5
916
+ - **NO separation** between actions and assertions objects. They are regular class methods
917
+ - All lifecycle methods (iStartMyUIComponent, iTeardownMyApp) are inherited from Opa5
918
+
919
+ ### Arrangements Pattern - Eliminated
920
+
921
+ DO NOT create separate Arrangements classes in TypeScript.
922
+
923
+ JavaScript often uses:
924
+ ```javascript
925
+ sap.ui.define(["sap/ui/test/Opa5"], (Opa5) => {
926
+ return Opa5.extend("namespace.Startup", {
927
+ iStartMyApp() { this.iStartMyUIComponent({...}); }
928
+ });
929
+ });
930
+ ```
931
+
932
+ TypeScript eliminates this - call `iStartMyUIComponent()` directly on the page instance in the journey.
933
+
934
+ ### OPA Test Registration (opaTests.qunit.ts)
935
+
936
+ JavaScript typically has:
937
+ ```javascript
938
+ sap.ui.define(["sap/ui/test/Opa5", "./arrangements/Startup", "./Journey1"], (Opa5, Startup) => {
939
+ Opa5.extendConfig({ arrangements: new Startup(), autoWait: true });
940
+ });
941
+ ```
942
+ TypeScript simplifies to:
943
+ ```typescript
944
+ // import all your OPA tests here
945
+ import "integration/HelloJourney";
946
+ ```
947
+
948
+ No Opa5.extendConfig() needed, just import the journeys.
949
+
950
+ ### Code Coverage in case of using `ui5-test-runner`
951
+
952
+ If (and only if!) the tests are set up using the `ui5-test-runner` tool, then the app must be started with a specific `ui5-coverage.yaml` configuration. Suitable `package.json` scripts may look like this:
953
+
954
+ ```
955
+ "start-coverage": "ui5 serve --port 8080 --config ui5-coverage.yaml",
956
+ ...
957
+ "test-runner-coverage": "ui5-test-runner --url http://localhost:8080/test/testsuite.qunit.html --coverage -ccb 60 -ccf 100 -ccl 80 -ccs 80",
958
+ "test-ui5": "ui5-test-runner --start start-coverage --url http://localhost:8080/test/testsuite.qunit.html --coverage -ccb 60 -ccf 100 -ccl 80 -ccs 80",
959
+ ```
960
+
961
+ The `test-runner-coverage` script expects `start-coverage` to be executed manually, `test-ui5` does it automatically.
962
+
963
+ When adding such scripts, explain them to the user!
964
+
965
+ The `ui5-coverage.yaml` file must configure the `ui5-tooling-transpile-middleware` like this by adding the `babelConfig`:
966
+
967
+ ```yaml
968
+ ...
969
+ server:
970
+ customMiddleware:
971
+ - name: ui5-tooling-transpile-middleware
972
+ afterMiddleware: compression
973
+ configuration:
974
+ debug: true
975
+ babelConfig:
976
+ sourceMaps: true
977
+ ignore:
978
+ - "**/*.d.ts"
979
+ presets:
980
+ - - "@babel/preset-env"
981
+ - targets: defaults
982
+ - - transform-ui5
983
+ - "@babel/preset-typescript"
984
+ plugins:
985
+ - istanbul
986
+ - name: ui5-middleware-livereload
987
+ afterMiddleware: compression
988
+ ```
989
+
990
+ In this case, the `babel-plugin-istanbul` package must be added as dev dependency! (The other packages in the config are already required by `ui5-tooling-transpile`).