Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
iljapostnovs opened this issue Feb 12, 2022 · 5 comments
Closed
Assignees
Labels
ts-interface-generator Related to the ts-interface-generator sub-package

Comments

@iljapostnovs
Copy link

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 akudev self-assigned this Feb 16, 2022
@akudev akudev closed this as completed in 183920f Mar 9, 2022
@akudev
Copy link
Contributor

akudev commented Mar 9, 2022

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
Copy link
Author

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 akudev added the ts-interface-generator Related to the ts-interface-generator sub-package label Mar 22, 2022
@akudev
Copy link
Contributor

akudev commented Mar 22, 2022

The next release has been created now (0.4.1).

@iljapostnovs
Copy link
Author

iljapostnovs commented Mar 22, 2022

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
Copy link
Contributor

akudev commented Mar 23, 2022

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 #346 to track it separately.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ts-interface-generator Related to the ts-interface-generator sub-package
Projects
None yet
Development

No branches or pull requests

2 participants