microsoft / microsoft/TypeScript

Allow omission of generic type if its equal to the default type

Đang mở
#41,724 2 bình luận 2 reaction 0 người được giao Xem trên GitHub

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

Awaiting More Feedback Suggestion
Ngôn ngữ chính
Go
Star
111k
Fork
14.3k
Merge trung bình
2 ngày 4 giờ
Pull request đã merge (30 ngày)
132

Mô tả

Search Terms

generic, default, extends, equals, =

Suggestion

Allow the syntax extends = T in generics definition in place of extends T = T.

Currently

class Foo <T extends any = any> {}

Suggestion*

class Foo <T extends= any> {}

Use Cases

The problem of having to write <T extends any = any> revealed itself when I had a bit more complex type looking like keyof NetworkTransportProtocol that looked then somehow like this:

class Foo<T extends keyof system.NetworkTransportProtocol = keyof system.NetworkTransportProtocol> {}

which just was a lot of duplicated text.

class Foo<T extends= keyof system.NetworkTransportProtocol> {}

by reducing the duplicate information the whole syntax becomes better to read.

While I did focus on the default-case for class-generics. I believe this could also help with other definitions:

function foo <T extends=any>(bar: T) {}

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

Issue không nêu tên các tệp triển khai hoặc test; hãy bắt đầu bằng cách tìm grammar và các test của TypeScript cho các ràng buộc generic và các kiểu mặc định. So sánh cú pháp extends= được đề xuất cho generic của class và function, sau đó xác định hành vi cần có của parser và quá trình kiểm tra kiểu. Công việc được xem là hoàn tất khi có một thiết kế được chấp nhận và coverage test đạt cho cú pháp được đề xuất.

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
Đình trệ
Độ rõ ràng
Khá 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.