microsoft / microsoft/TypeScript
Code fix spelling suggestions for class fields based on lexical scope
Nobody has claimed this yet.
- Dominant language
- Go
- Stars
- 111k
- Forks
- 14.4k
- Avg merge
- 1d 19h
- Merged PRs (30d)
- 117
Description
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?
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the spelling-suggestion code-fix discussion linked from the issue, including the referenced TypeScript pull request review. Compare the private-field example with the existing receiver-type suggestions and resolve the open questions about scope, precision, and performance; the issue does not name implementation files or tests, and completion criteria remain undecided.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript, typescript
- Domain
- devtools
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100