SAP / ui5-typescript

Tooling to enable TypeScript support in SAPUI5/OpenUI5 projects
https://sap.github.io/ui5-typescript
Apache License 2.0
201 stars 28 forks source link

@ui5/ts-interface-generator fails if there is no settings type #374

Closed iljapostnovs closed 2 years ago

iljapostnovs commented 2 years ago

@ui5/ts-interface-generator: 0.5.1 There are issues with classes which doesn't have settings type.

Error: CustomWebSocket inherits from EventProvider and has metadata but the parent class "sap/ui/core/ws/WebSocket".WebSocket seems to have no settings type. It might have no constructors, this is where the settings type is used.

In case this parent class is also in your project, make sure to add its constructors, then try again. A comment with instructions might be in the console output above.
Otherwise, you can temporarily remove this file (.../WebSocket.ts) from the project and try again to get the console output with the suggested constructors.
In any case, you need to make the parent parent class "sap/ui/core/ws/WebSocket".WebSocket have constructors with typed settings object to overcome this issue.

Generator fails on this and doesn't continue to generate the rest of the interfaces. Example: extending of WebSocket (https://ui5.sap.com/#/api/sap.ui.core.ws.WebSocket) Would it be possible to generate interfaces without settings type of the parent? I see that the second interface in .gen.d.ts file could be generated without parent. (which adds fire<Event>, detach<Event>, attach<Event> etc) If no, at least some configuration with file exclusions would be nice as well.

Thanks!

akudev commented 2 years ago

Seems to make sense, thanks!

akudev commented 2 years ago

Not everything is as it seems. Accessors are only generated for sub-classes of ManagedObject. An EventProvider does not get any attach*/detach*/fire* methods generated for its events. Hence there is also no need to create an interface with such methods.

The generation is triggered in ManagedObjectMetadata. You can see the difference at https://jsbin.com/topizem/1/edit?html,output

But still there is something wrong: the interface generator should not even try to handle this file. In fact I had wrongly added "EventProvider" as one of the "interesting" base classes for which interfaces need to be generated. Fix is coming. Thanks!

akudev commented 2 years ago

Fix is in https://www.npmjs.com/package/@ui5/ts-interface-generator/v/0.5.2

iljapostnovs commented 2 years ago

Didn't expect that EventProvider would not generate event related methods, but fair enough. Now it works fine, thanks a lot!

codeworrior commented 2 years ago

@iljapostnovs valid point reg. EventProvider and the generation of event related methods. However, I didn't find enough benefit in changing this, see https://github.com/SAP/openui5/issues/3084#issuecomment-992187635 .