[MatDialog]: Infer return-type `R` of `MatDialogRef<T, R>` based on component passed into `MatDialog.open()`
- Vorherrschende Sprache
- TypeScript
- Sterne
- 25k
- Forks
- 6.8k
- Ø Merge
- 1 T. 8 Std.
- Gemergte PRs (30 T.)
- 91
Beschreibung
### 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_
Beitragsleitfaden
Rechercherichtung
Beginne damit, die in diesem Issue beschriebenen Typings von MatDialog.open() und MatDialogRef zu lesen; verfolge dann, wie die an open() übergebene Komponente mit dem Ergebnis von afterClosed() zusammenhängt. Erledigt ist die Aufgabe, wenn der Ergebnistyp aus der Komponente abgeleitet wird, ohne dass Aufrufer ein explizites Return-Type-Generic angeben müssen, und der unterstützte Komponentenvertrag dokumentiert oder getestet ist.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Bewertung
- Tech-Stack
- angular, typescript
- Bereich
- frontend
- Issue-Typ
- Feature
- Schwierigkeit
- 5/5
- Geschätzter Aufwand
- Über eine Woche
- Aktivitätsstatus
- Veraltet
- Klarheit
- Muss geklärt werden
- Anfängerfreundlichkeit
- 35/100