microsoft / microsoft/TypeScript

Spreading tuple into generic/type arguments

Đang mở
#39,648 8 bình luận 37 reaction 0 người được giao Xem trên GitHub

Chưa có ai nhận issue này.

In Discussion Suggestion
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

Mở hướng dẫn đóng góp

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. 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.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. 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

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.