microsoft / microsoft/TypeScript
unique symbol lost on assignment to const despite type assertion
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
unique symbol widening
🕗 Version & Regression Information
- This is the behavior in every version I tried
⏯ Playground Link
💻 Code
const u = Symbol();
const a7 = u as typeof u // widened to symbol
🙁 Actual behavior
a7 is symbol
🙂 Expected behavior
a7 has typeof u
Additional information about the issue
This issue is a huge problem for isolated declarations as it breaks the assumption that in an expression const o = a as T we can always use T as the type of o. This is also inconsistent with the way similar expressions work for string/number literal types (ex)
Similar issues:
- https://github.com/microsoft/TypeScript/issues/43657 - Widening on return type not on variable declaration
- https://github.com/microsoft/TypeScript/issues/55361 - Similar, explicitly typed variable is widened
- https://github.com/microsoft/TypeScript/issues/36876 - Widening when assigning from object property (but no assertion)
- https://github.com/microsoft/TypeScript/issues/53276
@Andarist perhaps https://github.com/microsoft/TypeScript/pull/54778 also fixes this?
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 với TypeScript Playground được liên kết và so sánh các kiểu được suy luận cho phép assertion unique-symbol với các trường hợp tương tự của literal chuỗi và số. Theo dõi hành vi widening của compiler đối với các khai báo const và type assertion, sau đó xác minh rằng kiểu unique-symbol được assertion vẫn được giữ nguyên mà không gây hồi quy cho các trường hợp liên quan.
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
- Lỗi
- Độ khó
- 4/5
- Thời gian dự kiến
- 3-5 ngày
- Mức độ hoạt động
- Ít trao đổi
- Độ rõ ràng
- Khá rõ ràng
- Mức phù hợp với người mới
- 42/100