angular / angular/components

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

オープン
#31,873 コメント 2 件 リアクション 0 件 担当者 0 名 GitHub で見る
area: material/dialog P4
主要言語
TypeScript
スター
25k
フォーク
6.8k
平均マージ
1日 8時間
マージ済み PR(30日)
91

説明

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

コントリビューションガイド

コントリビューションガイドを開く

調査の方向性

リンクされた StackBlitz の再現コードから始め、MatDialogConfig.closePredicate と dialog.open の TypeScript 型定義を調査します。推論されたコールバックパラメーターと明示的に注釈が付けられたコールバックパラメーターを、想定される使用方法と比較します。完了の条件は、result、config、componentInstance の値が正しく型付けされた状態で再現コードがコンパイルできることです。

索引モデルが issue の本文から書いたものです。

評価

技術スタック
angular, typescript
領域
frontend
issue の種類
バグ
難易度
3/5
見積もり時間
1〜2日
活発さ
停滞
明瞭さ
おおむね明確
初心者へのやさしさ
45/100

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。