[MatDialog]: Infer return-type `R` of `MatDialogRef<T, R>` based on component passed into `MatDialog.open()`
- Ngôn ngữ chính
- TypeScript
- Star
- 25k
- Fork
- 6.8k
- Merge trung bình
- 1 ngày 8 giờ
- Pull request đã merge (30 ngày)
- 91
Mô tả
### 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_
Hướng dẫn đóng góp
Hướng nghiên cứu
Bắt đầu bằng cách đọc các typings của MatDialog.open() và MatDialogRef được mô tả trong issue, sau đó theo dõi mối quan hệ giữa component được truyền vào open() và kết quả của afterClosed(). Hoàn thành có nghĩa là kiểu kết quả được suy luận từ component mà không yêu cầu bên gọi cung cấp generic kiểu trả về tường minh, đồng thời contract của component được hỗ trợ đã được ghi lại hoặc kiểm thử.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Đánh giá
- Công nghệ
- angular, typescript
- Lĩnh vực
- frontend
- Loại issue
- Tính năng
- Độ khó
- 5/5
- Thời gian dự kiến
- Hơn một tuần
- Mức độ hoạt động
- Đình trệ
- Độ rõ ràng
- Cần làm rõ
- Mức phù hợp với người mới
- 35/100