Skip to content

bug(dialog): Typing of new MatDialogConfig.closePredicate #31873

@PowerKiKi

Description

@PowerKiKi

Is this a regression?

  • Yes, this behavior used to work in the previous version

The previous version in which this bug was not present was

No response

Description

#30919 introduced the new MatDialog config closePredicate. I am struggling to make typing work to have a 100% typed code.

Reproduction

StackBlitz link: https://stackblitz.com/edit/9wtzaa17?file=src%2Fmain.ts

Steps to reproduce:

  1. open link, it does not compile, but I expect to compile

Expected Behavior

At first I expected that types would be flowing, so that I wouldn't need to repeat them. So my expected usage would be like:

this.dialog.open<MyDialog, MyDialogData, MyDialogResult>(
  MyDialog,
  {
    closePredicate: (
      result,
      config,
      componentInstance
    ) => {
      return something();
    },
  }
);

But that failed to compile. So I tried to add typing like so:

this.dialog.open<MyDialog, MyDialogData, MyDialogResult>(
  MyDialog,
  {
    closePredicate: (
      result: MyDialogResult | undefined,
      config: MatDialogConfig<MyDialogData>,
      componentInstance: MyDialog | null
    ) => {
      return componentInstance?.animal() !== 'my original data';
    },
  }
);

That also fail to compile. And I am out of ideas.

Angular Material source never use this callback with any parameters (neither in implementation, nor in tests).

What is the expected usage pattern here ? Is there a way to avoid repetition ?

Actual Behavior

Stackblitz does not compile

Environment

  • Angular: 20.1
  • CDK/Material: 20.1
  • Browser(s): Chrome
  • TypeScript: 5.8.3

Metadata

Metadata

Assignees

No one assigned

    Labels

    P4A relatively minor issue that is not relevant to core functions

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions