microsoft / microsoft/TypeScript
Code fix spelling suggestions for class fields based on lexical scope
Nadie ha tomado este issue todavía.
- Lenguaje dominante
- Go
- Estrellas
- 111k
- Forks
- 14.4k
- Merge medio
- 1 d 19 h
- PR fusionados (30 d)
- 117
Descripción
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?
Guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Línea de trabajo
Comienza con la discusión sobre la corrección del código de sugerencias ortográficas enlazada desde el issue, incluida la revisión del pull request de TypeScript mencionada allí. Compara el ejemplo de campo privado con las sugerencias existentes sobre el tipo del receptor y resuelve las preguntas abiertas sobre el alcance, la precisión y el rendimiento; el issue no especifica archivos de implementación ni pruebas, y los criterios de finalización siguen sin decidirse.
Escrito por el modelo de indexación a partir del texto del issue.
Evaluación
- Stack tecnológico
- javascript, typescript
- Área
- devtools
- Tipo de issue
- Nueva funcionalidad
- Dificultad
- 5/5
- Tiempo estimado
- Más de una semana
- Estado de actividad
- Estancado
- Claridad
- Necesita aclaración
- Aptitud para principiantes
- 25/100