angular / angular/components

[MatDialog]: Infer return-type `R` of `MatDialogRef<T, R>` based on component passed into `MatDialog.open()`

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

説明

### Feature Description

If I call:

```
MatDialog
.open(ADialogComponent)
.afterClosed()
.subscribe((result) => {
// result should have a type rather than `any`
});
```

It would be nice if `result` could be typed based on what `ADialogComponent` is known to return. Perhaps some work would need to be done for a component to be able to specify its return type. Maybe it would need to implement an interface `MatDialogComponent` or something. I don't know the solution...I just know the current way leaves a lot of room for error.

As things are currently, the caller must specify the return type when calling `MatDialog.open()` like this:

```
MatDialog
.open(ADialogComponent)
.afterClosed()
.subscribe((result: ReturnTypeHere) => {
// result is typed as ReturnTypeHere because it was specified when calling MatDialog.open()
});
```

The gives the caller the opportunity to incorrectly specify the return type...or to not specify one at all.

### Use Case

_No response_

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

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

調査の方向性

まず、issue で説明されている MatDialog.open() と MatDialogRef の typings を読み、次に open() に渡されるコンポーネントが afterClosed() の結果とどのように関係するかを追跡します。完了の条件は、呼び出し側が明示的な戻り値型のジェネリックを指定しなくても、コンポーネントから結果の型が推論され、サポートされるコンポーネント契約が文書化またはテストされていることです。

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

評価

技術スタック
angular, typescript
領域
frontend
issue の種類
機能追加
難易度
5/5
見積もり時間
1週間以上
活発さ
停滞
明瞭さ
説明が足りない
初心者へのやさしさ
35/100

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

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