microsoft / microsoft/TypeScript

Allow `interface extends object` syntax

Đang mở
#60,730 2 bình luận 3 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

interface extends object

✅ Viability Checklist
⭐ Suggestion

I propose to allow the following syntax:

interface MyInterface extends object {}

This would have identical semantics to the following (currently legal) syntax:

type _object = object
interface MyInterface extends _object {}

Details:

  1. No primitive may be assigned to such an interface or an intersection containing such an interface
  2. This requirement is inherited by any extending interfaces

I'm requesting this feature mainly because it was the only pain-point mentioned in this related issue. To quote:

No one is going to turn on this behavior if it means every time they write

interface Person {
  name: string
}

they actually need to write

interface _PersonFields {
  name: string;
}
type Person = object & _PersonFields;

Regardless of the outcome of that other issue however, it would be nice to be able to extends object without going through that kind of hassle.

📃 Motivating Example

A small usability improvement to allow interfaces to more easily declare that primitives cannot be assigned to them.

💻 Use Cases
  1. What do you want to use this for? To avoid non-idiomatic verbosity
  2. What shortcomings exist with current approaches? Non-idiomatic verbosity
  3. What workarounds are you using in the meantime? Non-idiomatic verbosity

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 cú pháp interface extends object được đề xuất và issue liên quan #60582 được liên kết. Không có tệp triển khai hoặc bài kiểm thử nào được nêu, vì vậy hãy truy vết cách xử lý liên quan đến kế thừa interface và khả năng gán trước khi xác định các bài kiểm thử cho ngữ nghĩa gán kiểu nguyên thủy đã nêu.

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.