microsoft / microsoft/TypeScript
Spreading tuple into generic/type arguments
Chưa có ai nhận issue này.
- Ngôn ngữ chính
- Go
- Star
- 111k
- Fork
- 14.4k
- Merge trung bình
- 1 ngày 19 giờ
- Pull request đã merge (30 ngày)
- 117
Mô tả
Search Terms
- spreading generic parameters
- generic parameter spread
- tuple generic spread
- spreading generic argument
- spreading typeArgument
- spreading type argument
Suggestion
Allow spreading of a tuple type into type arguments.
The idea is that a tuple of n elements gets spread into generic arguments with r arguments. If n is larger than r, only the first r items are used. If n is smaller than r it is possible to add elements after the spread argument. E.g.
function foo<A, B, C, D>() {
}
type ThreeType = [Foo, Bar, Baz];
foo<...ThreeType, Delta>();
Use Cases
I find myself repeating complex generic types. Ideally I could shorten lengthy repetition into a single type.
Examples
dialog.open takes three generic arguments, these have to be repeated each call. This makes the call less legible and reduces DRYness.
const dialogRef = this.dialog.open<
PrinterSelectDialogComponent,
PrinterSelectDialogData,
OfferProductPrinter>(
PrinterSelectDialogComponent,
{
data: {
printer,
},
},
);
After this proposal
export type PrinterSelectDialog = [
PrinterSelectDialogComponent,
PrinterSelectDialogData,
OfferProductPrinter,
];
const dialogRef = this.dialog.open<...PrinterSelectDialog>(PrinterSelectDialogComponent, {
data: {
service,
},
});
Checklist
My suggestion meets these guidelines:
- This wouldn't be a breaking change in existing TypeScript/JavaScript code
- This wouldn't change the runtime behavior of existing JavaScript code
- This could be implemented without emitting different JS based on the types of the expressions
- This isn't a runtime feature (e.g. library functionality, non-ECMAScript syntax with JavaScript output, etc.)
- This feature would agree with the rest of TypeScript's Design Goals.
Hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Hướng nghiên cứu
Bắt đầu bằng cách xem xét đề xuất và các ví dụ của đề xuất về hành vi trải đối số generic dự kiến. Được xem là hoàn tất khi hỗ trợ tuple spread trong các đối số kiểu, bao gồm việc cắt bớt khi tuple dài hơn và các phần tử ở cuối khi tuple ngắn hơn, mà không thay đổi JavaScript được phát ra.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Đánh giá
- Công nghệ
- typescript
- Lĩnh vực
- compilers
- 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
- Sôi nổi
- Độ rõ ràng
- Đặc tả rõ ràng
- Mức phù hợp với người mới
- 35/100