[MatDialog]: Infer return-type `R` of `MatDialogRef<T, R>` based on component passed into `MatDialog.open()`
- Langage dominant
- TypeScript
- Étoiles
- 25k
- Forks
- 6.8k
- Merge moyen
- 1 j 8 h
- PR mergées (30 j)
- 91
Description
### 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_
Guide de contribution
Ouvrir le guide de contribution
Piste de recherche
Commencez par lire les typings de MatDialog.open() et de MatDialogRef décrits dans l'issue, puis suivez la relation entre le composant passé à open() et le résultat de afterClosed(). Le travail est terminé lorsque le type du résultat est inféré à partir du composant sans exiger des appelants qu'ils fournissent un générique explicite de type de retour, et que le contrat de composant pris en charge est documenté ou testé.
Rédigé par le modèle d'indexation à partir du texte de l'issue.
Évaluation
- Stack technique
- angular, typescript
- Domaine
- frontend
- Type d'issue
- Fonctionnalité
- Difficulté
- 5/5
- Temps estimé
- Plus d'une semaine
- Activité
- À l'abandon
- Clarté
- À clarifier
- Accessibilité débutants
- 35/100