microsoft / microsoft/TypeScript
Allow configuration of missing property quickfix
Nadie ha tomado este issue todavía.
- Lenguaje dominante
- Go
- Estrellas
- 111k
- Forks
- 14.3k
- Merge medio
- 2 d 4 h
- PR fusionados (30 d)
- 132
Descripción
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.
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 src/services/codefixes/fixAddMissingMember.ts alrededor de las líneas 204-210, la implementación identificada en la issue. Determina dónde el quickfix de miembro faltante elige la visibilidad de la propiedad y cómo una opción de configuración podría controlarla, incluido el caso de uso de un campo privado. Se considera terminado cuando el quickfix se puede configurar para generar una propiedad privada conservando el comportamiento predeterminado existente.
Escrito por el modelo de indexación a partir del texto del issue.
Evaluación
- Stack tecnológico
- typescript
- Área
- developer-experience, tooling
- Tipo de issue
- Nueva funcionalidad
- Dificultad
- 5/5
- Tiempo estimado
- Más de una semana
- Estado de actividad
- Estancado
- Claridad
- Bastante claro
- Aptitud para principiantes
- 35/100