microsoft / microsoft/TypeScript
Code fix spelling suggestions for class fields based on lexical scope
Nessuno ha ancora preso questa issue.
- Lingua principale
- Go
- Stelle
- 111k
- Fork
- 14.4k
- Merge medio
- 1g 19h
- PR unite (30g)
- 117
Descrizione
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?
Guida per i contributori
Apri la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Direzione di ricerca
Inizia con la discussione sulla correzione del codice per i suggerimenti ortografici collegata dall’issue, inclusa la revisione della pull request TypeScript indicata. Confronta l’esempio di campo privato con i suggerimenti esistenti sul tipo del ricevitore e risolvi le questioni aperte relative ad ambito, precisione e prestazioni; l’issue non indica file di implementazione né test, e i criteri di completamento restano da decidere.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- javascript, typescript
- Ambito
- devtools
- Tipo di issue
- Funzionalità
- Difficoltà
- 5/5
- Tempo stimato
- Più di una settimana
- Stato di attività
- Ferma
- Chiarezza
- Da chiarire
- Idoneità per principianti
- 25/100