angular / angular/components

bug(dialog): Typing of new `MatDialogConfig.closePredicate`

Offen
#31,873 2 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen
area: material/dialog P4
Vorherrschende Sprache
TypeScript
Sterne
25k
Forks
6.8k
Ø Merge
1 T. 8 Std.
Gemergte PRs (30 T.)
91

Beschreibung

### 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:

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

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

```ts
this.dialog.open(
MyDialog,
{
closePredicate: (
result: MyDialogResult | undefined,
config: MatDialogConfig,
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

Beitragsleitfaden

Beitragsleitfaden öffnen

Rechercherichtung

Beginne mit der verknüpften StackBlitz-Reproduktion und untersuche die TypeScript-Typdefinitionen für MatDialogConfig.closePredicate und dialog.open. Vergleiche implizit und explizit annotierte Callback-Parameter mit der erwarteten Verwendung; als erledigt gilt die Aufgabe, wenn die Reproduktion mit korrekt typisierten Werten für result, config und componentInstance kompiliert.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Bewertung

Tech-Stack
angular, typescript
Bereich
frontend
Issue-Typ
Bug
Schwierigkeit
3/5
Geschätzter Aufwand
1-2 Tage
Aktivitätsstatus
Veraltet
Klarheit
Größtenteils klar
Anfängerfreundlichkeit
45/100

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.