Anonymous Symbol Properties
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 5/5
- Thời gian dự kiến
- Hơn một tuần
- Mức phù hợp với người mới
- 35/100
- Loại issue
- Tính năng
- Độ rõ ràng
- Khá rõ ràng
- Mức độ hoạt động
- Sôi nổi
- Công nghệ
- typescript
- Lĩnh vực
- compilers
Hướng nghiên cứu
Bắt đầu từ các khai báo kiểu hiện tại và được đề xuất trong issue, rồi lần theo cách TypeScript xử lý các khóa thuộc tính được tính toán và danh tính của unique symbol. Công việc được xem là hoàn tất khi chấp nhận các khóa thuộc tính inline kiểu unique symbol, mỗi khai báo có một danh tính mới và vẫn giữ nguyên đầu ra JavaScript khi chạy; issue không nêu tên các tệp triển khai hoặc bài kiểm thử.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
🔍 Search Terms
"anonymous symbol properties"
"anonymous unique symbol"
"inline unique symbol"
"unique symbol property key"
"computed property unique symbol"
"symbol branding"
✅ Viability Checklist
- 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, new syntax sugar for JS, etc.)
- This isn't a request to add a new utility type: https://github.com/microsoft/TypeScript/wiki/No-New-Utility-Types
- This feature would agree with the rest of our Design Goals: https://github.com/Microsoft/TypeScript/wiki/TypeScript-Design-Goals
⭐ Suggestion
Allow unique symbol keys to be declared inline at the property declaration site.
📃 Motivating Example
Current code:
declare const brand: unique symbol;
type UserId = string & { readonly [brand]: "UserId" };
Proposed code:
type UserId = string & { readonly [brand: unique symbol]: "UserId" };
Each inline declaration would create a fresh symbol identity, equivalent to declaring a separate unique symbol and using it as the computed property key.
This is useful when a unique symbol property key is needed only once and does not need to be referenced independently. Common examples include phantom properties used for branded or refined types.
💻 Use Cases
-
What do you want to use this for?
Declaring single-useunique symbolproperty keys inline, particularly for phantom properties used by branded or refined types. -
What shortcomings exist with current approaches?
The current approach requires introducing a value-level declaration solely to provide a unique identity for a type-level property key. For single-use symbol keys, this creates an otherwise unnecessary binding in the surrounding scope. -
What workarounds are you using in the meantime?
Declaring a separateunique symbolvalue and using it as a computed property key.
- 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
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.
Issue khác của microsoft/TypeScript
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 88/100
microsoft/TypeScript#64322 · 2 bình luận · 1 reaction · 2 người được giao ·
-
Possible Improvement
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
microsoft/TypeScript#64278 · 1 bình luận · 1 reaction ·
-
Docs
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 70/100
microsoft/TypeScript#64118 · 1 bình luận ·
-
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 88/100
microsoft/TypeScript#64094 ·
-
Docs
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 76/100
microsoft/TypeScript#63959 · 5 bình luận ·
Tất cả issue của microsoft/TypeScript
Issue tương tự
-
kind/bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 88/100
kubernetes-sigs/prow#953 · 1 bình luận ·
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 88/100
caddyserver/caddy#8046 ·
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 86/100
-
L1 recommended for recruits
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 88/100
-
area/entangle bug
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 92/100