microsoft / microsoft/TypeScript

Confusing error on computed name class member

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

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

Domain: Error Messages Help Wanted Possible Improvement
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

late bindable computed symbol class member

🕗 Version & Regression Information
  • This is the behavior in every version I tried
⏯ Playground Link

https://www.typescriptlang.org/play/?target=99&lib=lib.esnext.d.ts&ts=5.9.0-dev.20250326#code/MYewdgzgLgBArmAlgRzgUwMoE8C2AjEAGwAYYBeGbfIgOgDMQAnACgCJWBKAbgCge6EwKInAwA5migBVJKky4CJZhwBcMKFgAOaEHXiz0VRaQDePGDEaS4jMPpSGFRYrwC+fYIQCGECDADChBAAzDBmFgDaEtIG8tRKHAC65DCsdIiM0KxuPEA

💻 Code
const uniqueSymbol0 = Symbol.for("");

function getUniqueSymbol0(): typeof uniqueSymbol0 {
  return uniqueSymbol0;
}

class Cls3 {
  [getUniqueSymbol0()] = "first"; // A computed property name in a class property declaration must have a simple literal type or a 'unique symbol' type.(1166)
}
🙁 Actual behavior

The error is confusing because this expression has a unique symbol type already

🙂 Expected behavior

This error should mention more accurate late-bindable requirements. From the source code:

    /**
     * Indicates whether a declaration name is definitely late-bindable.
     * A declaration name is only late-bindable if:
     * - It is a `ComputedPropertyName`.
     * - Its expression is an `Identifier` or either a `PropertyAccessExpression` an
     * `ElementAccessExpression` consisting only of these same three types of nodes.
     * - The type of its expression is a string or numeric literal type, or is a `unique symbol` type.
     */
Additional information about the issue

No response

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 với ví dụ TypeScript Playground được liên kết và chú thích trong mã nguồn mô tả các tên khai báo chắc chắn có thể liên kết muộn. Theo dõi chẩn đoán cho thuộc tính lớp được tính toán và điều chỉnh cách diễn đạt của nó để phản ánh các yêu cầu đã nêu về biểu thức và kiểu; xác minh rằng ví dụ báo cáo lỗi chính xác hơn.

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
Đì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.