Skip to content

fix(ts-interface-generator): properly type getters for properties of type object and function - #565

Merged
akudev merged 1 commit into
UI5:mainfrom
wridgeu:fix/properly-type-getters
May 11, 2026
Merged

akudev merged 1 commit into
UI5:mainfrom
wridgeu:fix/properly-type-getters

Conversation

@wridgeu

@wridgeu wridgeu commented Apr 13, 2026

Copy link
Copy Markdown
Contributor

For types like object or function the default value was/is not respected when generating accessors. The getter would/is wrongly typed when no callbacks/fns are provided to control properties.

So that a definition of
someFunc: { type: "function", group: "Behavior", defaultValue: null }

correctly generates :
getSomeFunc(): Function | null;

instead of:
getSomeFunc(): Function

I'm not that deep in the code base but have noticed that not all types have tests (though, I patched this locally in a project of mine so ... it works) and also that this change could maybe live somewhere in function generateMethods. Cases like this one, albeit a rather unusual one, would not be covered today (probably rather a wrong definition in UI5 itself and thus user/dev error more more than anything else).

Some more examples of similar definitions within UI5 ...

So that a definition of
`someFunc: { type: "function", group: "Behavior", defaultValue: null }`

correctly generates :
`getSomeFunc(): Function | null;`
@wridgeu wridgeu changed the title fix(ts-interface-generator): properly type getters fix(ts-interface-generator): properly type getters for properties of type object and function Apr 13, 2026
@akudev
akudev requested review from codeworrior May 11, 2026 11:14
@akudev

akudev commented May 11, 2026

Copy link
Copy Markdown
Member

In detail, it's not defaultValue: null which leads to the null in the type, but the fact that that in sap/ui/base/DataType.js the default for properties of type function oder object is null ist.
defaultValue: null only means there is no local default, but use the default from the type.

But this doesn't affect the change. Thanks!

The change is breaking, of course, for those who have written code relying on those properties of custom controls never returning null: the TS compiler will complain it could also be null. But this is a correctness fix. And the next release is breaking anyway due to other changes. Trying to reflect this in the commit message.

@akudev
akudev merged commit f2502fe into UI5:main May 11, 2026
7 checks passed
@wridgeu

wridgeu commented May 11, 2026

Copy link
Copy Markdown
Contributor Author

TIL! Thank you @akudev for the quick excursion & the merge! 🐦‍🔥

For anyone interested, see here wrt. the defaultValue declaration. :)

@wridgeu
wridgeu deleted the fix/properly-type-getters branch May 11, 2026 14:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants