angular / angular/components

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

Abierto
#24,538 15 comentarios 51 reacciones 0 asignados Ver en GitHub
area: material/dialog feature P3
Lenguaje dominante
TypeScript
Estrellas
25k
Forks
6.8k
Merge medio
1 d 8 h
PR fusionados (30 d)
91

Descripción

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

Guía de contribución

Abrir la guía de contribución

Línea de trabajo

Empieza leyendo los typings de MatDialog.open() y MatDialogRef descritos en el issue; después, sigue cómo se relaciona el componente pasado a open() con el resultado de afterClosed(). Se considera terminado cuando el tipo del resultado se infiere a partir del componente sin requerir que los llamadores proporcionen un genérico explícito para el tipo de retorno, y el contrato de componente compatible está documentado o probado.

Escrito por el modelo de indexación a partir del texto del issue.

Evaluación

Stack tecnológico
angular, typescript
Área
frontend
Tipo de issue
Nueva funcionalidad
Dificultad
5/5
Tiempo estimado
Más de una semana
Estado de actividad
Estancado
Claridad
Necesita aclaración
Aptitud para principiantes
35/100

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.