UI5 / UI5/typescript

Type 'import("sap/ui/core/Popup").Dock' is not assignable to type 'typeof Dock' (since UI5 1.115.0)

Open
#466 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
TypeScript
Stars
213
Forks
35
Avg merge
37m
Merged PRs (30d)
1

Description

Describe the bug
Since UI5 1.115.0, the TS types use a different strategy for enums attached to another API. They are no longer named exports, but attached as static properties.

When such an enum (e.g. Dock), exported as static property of a class (e.g. Popup.Dock), is used in the signature of yet another class (e.g. MessageToast), then the signature of that other class is broken. For a detailed example see https://github.com/SAP/openui5/issues/4091.

Expected behavior
Any usage of such an enum in another API should work seamlessly.

Additional context
The problem is that the "usage in yet another class" currently uses the static property to refer to the type:

  import Popup from "sap/ui/core/Popup";

  interface MessageToast {
    show(
      msg: string,
      at: typeof Popup.Dock // <-- problem
    )
    ...

Unfortunately, this is not the same as the original enum. According to my experiments, it would be better to

  import type {Dock} from "sap/ui/core/Popup"; // ideally, import as type

  interface MessageToast {
    show(
      msg: string,
      at: Dock // <-- better declaration of type
    )
    ...

Interestingly, this works already today as the enum Dock is exported from Popup (any declaration in an ambient module declaration is implicitly an export, even without the keyword export).

Contributor guide

Open the contributing guide

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.

Research direction

Start with the TypeScript declarations for sap/ui/core/Popup and MessageToast, focusing on how Popup.Dock is referenced in MessageToast.show. Verify the completed change by checking that Dock is accepted there without the typeof mismatch and that the documented example type-checks.

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
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.