Recursive types don't work for sap.ui.model.json.TypedJSONModel
Nobody has claimed this yet.
Assessment
- Difficulty
- 5/5
- Estimated time
- Over a week
- Newbie friendliness
- 35/100
- Issue type
- Bug
- Clarity
- Needs clarification
- Activity status
- Stale
- Tech stack
- typescript
- Domain
- frontend
Research direction
Start by locating the TypeScript definition and implementation entry point for sap.ui.model.json.TypedJSONModel, then reproduce the recursive Order and OrderItems example from the issue. Investigate how getProperty derives nested paths and determine an agreed limit or other handling for recursive types; done means the example type-checks without making recursive models unusable.
Written by the indexing model from the issue text.
Description
Hello there.
Describe the bug
There is an issue with sap.ui.model.json.TypedJSONModel if recursive types are used.
Let's say we have something like this:
import TypedJSONModel from "sap/ui/model/json/TypedJSONModel";
type OrderItems = {
OrderId: string;
Id: string;
to_Order?: Order;
};
type Order = {
Id: string;
to_OrderItems?: { results: OrderItems[] };
};
/**
* @namespace xxx
*/
export default class TestJSONModel extends TypedJSONModel<typeof TestJSONModel._mInitialData> {
private static readonly _mInitialData = {
Orders: [] as Order[]
};
test() {
// errors here
const value = this.getProperty("/Orders/0/to_OrderItems/results");
}
}
We get errors:
Which does make sense, of course, but it makes this model unusable for types generated for OData Entities, because they can be indeed recursive.
The example above demonstrates that. So, we have an Order, which can have OrderItem[], and OrderItem may have Order. It goes into recursive and kills the types.
Expected behavior
There should be a possibility to use types, even if they are recursive.
I actually had developed typed JSONModel by myself couple of years ago, and I solved this issue by adding Depth, which sets the max number of inner properties to be accessible.
Let's say we have /Orders/0/to_OrderItems/results as in example above. The depth here would be 4.
/ -> Depth 0
/Orders -> Depth 1
/Orders/0 -> Depth 2
etc.
So I would propose to have that in the TypedJSONModel.
If there are better ideas - would be nice hear them out.
- Dominant language
- TypeScript
- Stars
- 213
- Forks
- 35
- Avg merge
- 37m
- Merged PRs (30d)
- 1
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.
More from UI5/typescript
-
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
UI5/typescript#625 · 4 comments ·
-
dts-generator
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
UI5/typescript#529 · 3 comments ·
-
Dependency Dashboard Open
Difficulty 5/5 Over a week Newbie friendliness 15/100
UI5/typescript#587 ·
-
enhancement ts-interface-generator
Difficulty 5/5 Over a week Newbie friendliness 30/100
UI5/typescript#524 ·
-
Difficulty 5/5 Over a week Newbie friendliness 25/100
UI5/typescript#520 · 3 comments ·
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 84/100
Eynzof/Hermes-CN-Desktop#610 ·
-
bug clawsweeper:linked-pr-open clawsweeper:needs-live-repro clawsweeper:no-new-fix-pr impact:message-loss issue-rating: 🐚 platinum hermit P2 regression
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
-
enhancement
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
-
calcite-components needs triage refactor
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
Esri/calcite-design-system#15203 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 90/100
danielmiessler/LifeOS#2218 ·