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

ts-interface-generator: interface is not generated in multiple scenarios #337

Closed iljapostnovs closed 2 years ago

iljapostnovs commented 2 years ago

ts-interface-generator version: 0.4.0

Interface for ManagedObject children is not generated: image

Interface for second+ level children of Control is not generated: image

image

akudev commented 2 years ago

Hi Ilja, thanks for the issue report! I just fixed it, so this issue will be gone with the next release. But #338 is not addressed yet.

Note that type "number" is not allowed for UI5 properties, only "int" or "float" - see https://ui5.sap.com/#/api/sap.ui.base.ManagedObject%23methods/sap.ui.base.ManagedObject.extend

Thanks and regards Andreas

iljapostnovs commented 2 years ago

Hi @akudev,

Thanks a lot!

Note that type "number" is not allowed for UI5 properties, only "int" or "float" - see https://ui5.sap.com/#/api/sap.ui.base.ManagedObject%23methods/sap.ui.base.ManagedObject.extend

Yeah, silly mistake by me. I was aware of that, but I guess my data typing was "typescripted" away for this issue :)

akudev commented 2 years ago

The next release has been created now (0.4.1).

iljapostnovs commented 2 years ago

Hi @akudev, Thanks for letting me know!

I'm receiving an error for this case using v0.4.1: image

\ui5-typescript-helloworld\node_modules\@ui5\ts-interface-generator\dist\interfaceGenerationHelper.js:97
                                throw new Error(`${statement.name ? statement.name.text : ""} inherits from ${interestingBaseClass} but the parent class ${typeChecker.getFullyQualifiedName(type.getSymbol())} seems to have no settings type`);
                                ^

Error: OneMoreControl inherits from Control but the parent class "/ui5-typescript-helloworld/src/control/MyControl".MyControl seems to have no settings type
    at \ui5-typescript-helloworld\node_modules\@ui5\ts-interface-generator\dist\interfaceGenerationHelper.js:97:39
    at Array.forEach (<anonymous>)
    at \ui5-typescript-helloworld\node_modules\@ui5\ts-interface-generator\dist\interfaceGenerationHelper.js:69:46
    at Array.forEach (<anonymous>)
    at \ui5-typescript-helloworld\node_modules\@ui5\ts-interface-generator\dist\interfaceGenerationHelper.js:67:43
    at Array.forEach (<anonymous>)
    at getManagedObjects (\ui5-typescript-helloworld\node_modules\@ui5\ts-interface-generator\dist\interfaceGenerationHelper.js:63:27)
    at generateInterfaces (\ui5-typescript-helloworld\node_modules\@ui5\ts-interface-generator\dist\interfaceGenerationHelper.js:39:17)
    at \ui5-typescript-helloworld\node_modules\@ui5\ts-interface-generator\dist\generateTSInterfaces.js:133:60
    at Array.forEach (<anonymous>)
akudev commented 2 years ago

Hi @iljapostnovs, I see... the generator tries to find the settings type of the parent class (to make its own settings type inherit from it). The settings type can only be found in the constructor signatures. The problem is that at this time the parent class (MyControl) does not have any constructors yet. You know, the constructors are suggested in the console output of the generator and need to be added by hand. In the situation you showed, there is already the suggested output for MyControl constructors:

NOTE:
Class MyControl in file [c:/.../git/ui5-typescript/packages/ts-interface-generator/src/test/testdata/testControl/MyControl.ts]() needs to contain the following constructors, in order to make TypeScript aware of the possible constructor settings. Please copy&paste the block manually, as the ts-interface-generator will not touch your source files:
===== BEGIN =====
// The following three lines were generated and should remain as-is to make TypeScript aware of the constructor signatures
constructor(idOrSettings?: string | $MyControlSettings);
constructor(id?: string, settings?: $MyControlSettings);
constructor(id?: string, settings?: $MyControlSettings) { super(id, settings); }
===== END =====

Once the suggested constructors are added to MyControl, the next run of the generator does succeed. This is what I would suggest as temporary workaround.

I'm not sure whether the scenario is likely to happen - at least when MyControl is developed first, the constructors should already be added in the beginning and then creating OneMoreControl will succeed just fine. But apparently you encountered the scenario. Maybe the hint to add the constructors should be made clearer. Or maybe not doing so should result in an error?

But of course I can also try to handle this case. After all, all the way up the chain there is a UI5 base class with well-defined settings type. Might be a bit tricky, though, to get there in this stage of the generation, orthogonal to the regular flow... I'll have to check. A first improvement could be to mention this possibility and workaround in the error message.

Thanks for reporting! I opened https://github.com/SAP/ui5-typescript/issues/346 to track it separately.