microsoft / microsoft/TypeScript
Allow configuration of missing property quickfix
Personne n'a encore pris cette issue.
- Langage dominant
- Go
- Étoiles
- 111k
- Forks
- 14.4k
- Merge moyen
- 1 j 19 h
- PR mergées (30 j)
- 117
Description
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.
Guide de contribution
Ouvrir le guide de contribution
Par où commencer
- Lisez l'issue en entier, puis le guide de contribution du projet.
- Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
- Forkez le dépôt et travaillez sur une branche.
- Ouvrez une pull request qui référence le numéro de l'issue.
Piste de recherche
Commencez par src/services/codefixes/fixAddMissingMember.ts autour des lignes 204-210, l’implémentation identifiée dans l’issue. Déterminez où le quickfix de membre manquant choisit la visibilité de la propriété et comment une option de configuration pourrait la contrôler, y compris le cas d’utilisation d’un champ privé. Le travail est terminé lorsque le quickfix peut être configuré pour générer une propriété privée tout en conservant le comportement par défaut existant.
Rédigé par le modèle d'indexation à partir du texte de l'issue.
Évaluation
- Stack technique
- typescript
- Domaine
- developer-experience, tooling
- Type d'issue
- Fonctionnalité
- Difficulté
- 5/5
- Temps estimé
- Plus d'une semaine
- Activité
- À l'abandon
- Clarté
- Plutôt claire
- Accessibilité débutants
- 35/100