microsoft / microsoft/TypeScript
[feature] class properties that are "readonly in public, writable in private" or other permutations
Personne n'a encore pris cette issue.
- Langage dominant
- Go
- Étoiles
- 111k
- Forks
- 14.3k
- Merge moyen
- 1 j 19 h
- PR mergées (30 j)
- 117
Description
Search Terms
typescript readonly on the outside writable on the inside
Suggestion
Some sort of syntax to describe readonly on the outside, writeable on the inside for a given property, so we can avoid making a getter just for this purpose (or using any of the convoluted options linked in that StackOverflow post).
Use Cases
To make this pattern easier to express.
Examples
instead of having to write
class Foo {
private _foo = 123
get foo() {
return this._foo
}
changeIt() {
this._foo = 456
}
}
const f = new Foo
f.foo = 345 // ERROR
we would be able to write something shorter like
class Foo {
publicread foo = 123
changeIt() {
this.foo = 456
}
}
const f = new Foo
f.foo = 345 // ERROR
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
Aucun fichier, test ou point d’entrée n’est nommé. Commencez par examiner la syntaxe proposée, l’exemple basé sur un getter et la discussion de 66 commentaires afin de comprendre les permutations non résolues et les contraintes de conception. Le travail serait considéré comme terminé lorsqu’un accord sur la syntaxe de la fonctionnalité et son comportement de vérification des types aura été trouvé avant de pouvoir définir le périmètre de l’implémentation.
Rédigé par le modèle d'indexation à partir du texte de l'issue.
Évaluation
- Stack technique
- typescript
- Domaine
- compilers
- Type d'issue
- Fonctionnalité
- Difficulté
- 5/5
- Temps estimé
- Plus d'une semaine
- Activité
- À l'abandon
- Clarté
- Plutôt claire
- Accessibilité débutants
- 25/100