[feature] class properties that are "readonly in public, writable in private" or other permutations
See original GitHub issueSearch 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.
Issue Analytics
- State:
- Created 4 years ago
- Reactions:162
- Comments:65 (3 by maintainers)
Top Results From Across the Web
typescript - A property that is read-only outside of the class, but ...
A second private property xValue can be declared. It would contain the value and be editable from inside. The public property x would...
Read more >Feature Class properties—ArcGIS Pro | Documentation
For a feature class, the Describe dataType property returns a value of "FeatureClass". Properties. Property, Explanation, Data Type. featureType. (Read Only).
Read more >explicit-member-accessibility - TypeScript ESLint
TypeScript allows placing explicit public , protected , and private accessibility modifiers in front of class members. The modifiers exist solely in the ......
Read more >TypeScript: JavaScript With Syntax For Types.
TypeScript extends JavaScript by adding types to the language. TypeScript speeds up your development experience by catching errors and providing fixes ...
Read more >Making a read-only attribute - Python Morsels
We can't assign to area because properties are read-only by default. We could try to make our length attribute into a property, by...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
This is one of the features I miss so much in TypeScript.
I don’t really like the
publicread privatewrite
notation. Is there an other language that uses that notation?Here are a few suggestions:
My choice would be the Swift style (option 1) or C# style (option 2). Option 3 is for if we can’t change the property definition.
Any progress on this?