microsoft / microsoft/TypeScript
Allow configuration of missing property quickfix
まだ誰も着手していません。
- 主要言語
- Go
- スター
- 111k
- フォーク
- 14.4k
- 平均マージ
- 1日 19時間
- マージ済み PR(30日)
- 117
説明
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.
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
調査の方向性
Issue で特定された実装である、204-210 行付近の src/services/codefixes/fixAddMissingMember.ts から始めてください。missing-member quickfix がプロパティの可視性をどこで選択しているか、また private-field のユースケースを含め、設定オプションでそれをどのように制御できるかを確認してください。quickfix を設定して private プロパティを生成でき、既存のデフォルト動作が維持されれば完了です。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- typescript
- 領域
- developer-experience, tooling
- issue の種類
- 機能追加
- 難易度
- 5/5
- 見積もり時間
- 1週間以上
- 活発さ
- 停滞
- 明瞭さ
- おおむね明確
- 初心者へのやさしさ
- 35/100