-
Notifications
You must be signed in to change notification settings - Fork 30
Description
Describe the bug
This is about the dataReceived event of the v4.OdataModel.
Currently it is generated in sap.ui.core.d.ts
as follows
export type ODataModel$DataReceivedEvent = Event<
ODataModel$DataReceivedEventParameters,
ODataModel
>;
Having a Fiori Elements list report extension causes the following type error
static overrides = {
routing: {
onAfterBinding (this: ListReportExtension) {
(this.getView().getModel() as ODataModel).attachDataReceived((event: ODataModel$DataReceivedEvent) => {
if ((event.getSource() as Binding).getPath?.() !== "/Foo") { // <-- type error TS2352
return;
}
// some important foo
}
}
}
}
type error is TS2352: Conversion of type ODataModel to type Binding may be a mistake because neither type sufficiently overlaps with the other. If this was intentional, convert the expression to unknown first.
The debug console shows that the return type is actually a Binding and not an ODataModel
event.getSource() instanceof sap.ui.model.Binding
=> true
event.getSource() instanceof sap.ui.model.odata.v4.ODataModel
=> false
Seems like in case of this event (not sure if there are others as well) the getSource()
method does not return and instance of the odata model as assumed by the generator but the model binding.
The event documentation looked ok for me that's why I open this issue here because it might be an issue with the generator.
Expected behavior
the following manual adjustment of the generated type fixed the issue
export type ODataModel$DataReceivedEvent = Event<
ODataModel$DataReceivedEventParameters,
Binding
>;