microsoft / microsoft/TypeScript
Code fix spelling suggestions for class fields based on lexical scope
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ả
Suggestion
Issue raised to separately track discussion started here: https://github.com/microsoft/TypeScript/pull/44648/files#r709632217 as suggested by @sandersn
Right now code fix spelling suggestions for property names are based on the receiver type. When the receiver type is wide, perhaps unknown, further correct candidate names could be collected from the fields in any surrounding classes. This could potentially only apply to private fields, where they can only be used within the class, or extended to all fields.
🔍 Search Terms
spelling, suggestion, code fix, class fields, private fields
✅ Viability 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, new syntax sugar for JS, etc.)
- This feature would agree with the rest of TypeScript's Design Goals.
⭐ Suggestion
📃 Motivating Example
class MyClass {
#brand;
static isMyClass(v: object): v is MyClass {
return #brad in v; // provide code-fix here: change 'brad' to 'brand'
}
}
Private field lookup, unlike traditional property look up, is scoped to within the class. This provides a finite, and lexically discoverable, set of candidate field names.
💻 Use Cases
The reciever type can be too wide to use for candidate names in these cases:
- type narrowing checks https://github.com/tc39/proposal-private-fields-in-in
- JavaScript files where static type information has not been added with JSDoc comments.
❔ Questions
- How much does it improve real-world recall?
- How much does it hurt precision?
- Should it only apply to #privates?
- Does iterated lookup hurt performance? (Probably not, but worth thinking about a little.)
- When the type is explicitly any or unknown, shouldn't the editor first suggest a specific type or narrowing for the receiver?
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 cuộc thảo luận về việc sửa mã gợi ý chính tả được liên kết từ issue, bao gồm cả phần review pull request TypeScript được tham chiếu. So sánh ví dụ về trường private với các gợi ý hiện có về kiểu receiver và giải quyết các câu hỏi còn bỏ ngỏ về phạm vi, độ chính xác và hiệu năng; issue không nêu tên các tệp triển khai hoặc bài kiểm thử, và tiêu chí hoàn thành vẫn chưa được quyết định.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Đánh giá
- Công nghệ
- javascript, typescript
- Lĩnh vực
- devtools
- 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
- Cần làm rõ
- Mức phù hợp với người mới
- 25/100