IssueRaiser

[feature] class properties that are "readonly in public, writable in private" or other permutations

<!-- 🚨 STOP 🚨 𝗦𝗧𝗒𝗣 🚨 𝑺𝑻𝑢𝑷 🚨 Half of all issues filed here are duplicates, answered in the FAQ, or not appropriate for the bug tracker. Please help us by doing the following steps before logging an issue: * Search: https://github.com/Microsoft/TypeScript/search?type=Issues * Read the FAQ, especially the "Common Feature Requests" section: https://github.com/Microsoft/TypeScript/wiki/FAQ --> ## Search Terms [typescript readonly on the outside writable on the inside](https://www.google.com/search?q=typescript%20readonly%20on%20the%20outside%20writable%20on%20the%20inside&cad=h) - https://stackoverflow.com/questions/46634876/how-can-i-change-a-readonly-property-in-typescript ## 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 ```ts 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 ```ts class Foo { publicread foo = 123 changeIt() { this.foo = 456 } } const f = new Foo f.foo = 345 // ERROR ``` ## Checklist My suggestion meets these guidelines: * [x] This wouldn't be a breaking change in existing Typ

Posted by trusktr on Mar 20, 2020, 3:24 AM

Tags

Related issues

Raise real-world problems, find people facing the same issue, and discuss solutions.3,500 issues0 comments

github (Software)

[feature] class properties that are "readonly in public, writable in private" or other permutations

trusktrMar 20, 2020, 3:24 AM

<!-- 🚨 STOP 🚨 𝗦𝗧𝗒𝗣 🚨 𝑺𝑻𝑢𝑷 🚨 Half of all issues filed here are duplicates, answered in the FAQ, or not appropriate for the bug tracker. Please help us by doing the following steps before logging an issue: * Search: https://github.com/Microsoft/TypeScript/search?type=Issues * Read the FAQ, especially the "Common Feature Requests" section: https://github.com/Microsoft/TypeScript/wiki/FAQ --> ## Search Terms [typescript readonly on the outside writable on the inside](https://www.google.com/search?q=typescript%20readonly%20on%20the%20outside%20writable%20on%20the%20inside&cad=h) - https://stackoverflow.com/questions/46634876/how-can-i-change-a-readonly-property-in-typescript ## 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 ```ts 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 ```ts class Foo { publicread foo = 123 changeIt() { this.foo = 456 } } const f = new Foo f.foo = 345 // ERROR ``` ## Checklist My suggestion meets these guidelines: * [x] This wouldn't be a breaking change in existing Typ

Comments (0)

No comments yet. Start the discussion.

Comment on this issue