[TypeScript] AggregationBindingInfo#groupHeaderFactory incorrectly restricts group keys to string

Open Beginner friendly
#4,489 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
72/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Domain
api, backend

Research direction

Start with the AggregationBindingInfo typedef in src/sap.ui.core/src/sap/ui/base/ManagedObject.js, which the issue links, and inspect how its groupHeaderFactory key type reaches types/sap.ui.core.d.ts. Check the Sorter documentation cited in the report for the supported primitive group values. Done when the generated declaration accepts string, boolean, and number keys without rejecting valid grouping callbacks.

Written by the indexing model from the issue text.

Description

documentation in progress
What is the issue and how can we reproduce it?

Title

Incorrect groupHeaderFactory parameter type: group keys are not limited to strings

Description

In @sapui5/types version 1.153.0, AggregationBindingInfo.groupHeaderFactory is declared as:

groupHeaderFactory?: (p1: { key: string }) => ManagedObject;

The key type is too restrictive. When grouping an OData list by an entity property, the group key depends on the property's runtime type. It can also be a boolean or number, for example when grouping by an Edm.Boolean or Edm.Int32 property.

The sap.ui.model.Sorter documentation explicitly states that grouping can use the raw model property value and that primitive group values are passed to groupHeaderFactory as the key property.

Steps To Reproduce

Bind a list to an OData entity set containing a Boolean property named IsActive, and enable grouping on that property:

import GroupHeaderListItem from "sap/m/GroupHeaderListItem";
import Sorter from "sap/ui/model/Sorter";

list.bindItems({
    path: "/Entities",
    template: itemTemplate,
    sorter: new Sorter("IsActive", false, true),
    groupHeaderFactory: group => new GroupHeaderListItem({
        title: group.key === true ? "Active" : "Inactive"
    })
});

TypeScript reports that comparing string and boolean is invalid, although group.key can be a Boolean at runtime. Grouping by a numeric property causes the equivalent type mismatch.

Expected Behaviour

The callback parameter should allow non-string group keys. At minimum:

groupHeaderFactory?: (
    p1: { key: string | boolean | number }
) => ManagedObject;

Actual Behaviour

The generated definition restricts key to string, requiring unnecessary type workarounds for valid grouping scenarios.

Environment

Which OpenUI5 version is your project targeting?

1.153.0

Is the issue device- or browser-specific?

No response

Confirmation
  • I have searched the existing issues and reviewed the relevant documentation as well as the API reference.
  • I am not disclosing any internal or sensitive information.
Dominant language
JavaScript
Stars
3.3k
Forks
1.3k
PR merge metrics
No merged PRs in 30d

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from UI5/openui5

All issues in UI5/openui5

Similar issues

More JavaScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.