Wrong source type for generated type ODataModel$DataReceivedEvent
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 213
- Forks
- 35
- Avg merge
- 37m
- Merged PRs (30d)
- 1
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
>;
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the generated sap.ui.core.d.ts declaration for ODataModel$DataReceivedEvent and trace the generator input for the ODataModel dataReceived event. Compare the generated source type with the runtime behavior and the event documentation; done when the generated event type reflects the actual Binding source rather than ODataModel.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 38/100