microsoft / microsoft/TypeScript
Allow configuration of missing property quickfix
Chưa có ai nhận issue này.
- 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
property does not exist quickfix
quick fix
create private property
quickfix configuration
Suggestion
When referencing a property that doesn't exist within a class, you get the error Property 'foo' does not exist on type 'MyClass'.ts(2339). In VS Code you can then do cmd-. to get the quickfix option Declare property 'foo'. When you select this, a property is declared, but it is created with default visibility.
Based on digging in to the code here:
https://github.com/microsoft/TypeScript/blob/15daf42b2c0bc4f06970c9e4688f1a93bff0f7a0/src/services/codefixes/fixAddMissingMember.ts#L204-L210
it doesn't look like there's anyway to configure this.
It would be really nice if there was a way to configure the quickfix functionality to default to creating properties with a given access modifier (in my case I'd like to default them to private). Given the upcoming #field private-named fields stuff, it seems like this could also be a useful way to let people decide what they want to use.
Use Cases
I would like to have the properties created by quickfix all start as private, to encourage writing classes with strong encapsulation.
The current approach requires me to go back and modify the generated declaration every time.
Examples
Starting code with missing property:
export class MyClass {
public constructor(foo: number) {
this.foo = foo;
}
}
After applying the quickfix to the line this.foo = foo; it becomes:
export class MyClass {
foo: number;
public constructor(foo: number) {
this.foo = foo;
}
}
but I would like some way to configure it to instead do:
export class MyClass {
private foo: number;
public constructor(foo: number) {
this.foo = foo;
}
}
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, etc.)
- This feature would agree with the rest of TypeScript's Design Goals.
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 src/services/codefixes/fixAddMissingMember.ts quanh các dòng 204-210, phần triển khai được xác định trong issue. Xác định nơi quickfix cho member bị thiếu chọn khả năng hiển thị của property và cách một tùy chọn cấu hình có thể kiểm soát điều đó, bao gồm cả trường hợp sử dụng private field. Hoàn tất có nghĩa là quickfix có thể được cấu hình để tạo một private property trong khi vẫn giữ nguyên hành vi mặc định hiện có.
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
- developer-experience, tooling
- 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