-
Notifications
You must be signed in to change notification settings - Fork 13k
Open
Labels
Awaiting More FeedbackThis means we'd like to hear from more people who would be helped by this featureThis means we'd like to hear from more people who would be helped by this featureSuggestionAn idea for TypeScriptAn idea for TypeScript
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.
snarfblam, giacomocusinato, fidlip, Exeteres, rafaelkallis and 204 moreLastDragon-ru, yume-chan and hiepxanhworstpractice, p0vidl0, sviat9440, EvanWard97, glyph-cat and 2 moreworstpractice, SanjeetKamboj, EvanWard97, p0vidl0, romsahel and 7 moremixtur, SanjeetKamboj, ifeltsweet, sidzan, RaniAgus and 12 moreSanjeetKamboj, tukusejssirs, worstpractice, p0vidl0, ryu-liam and 1 more
Metadata
Metadata
Assignees
Labels
Awaiting More FeedbackThis means we'd like to hear from more people who would be helped by this featureThis means we'd like to hear from more people who would be helped by this featureSuggestionAn idea for TypeScriptAn idea for TypeScript