Suggestion for readonly interface
See original GitHub issueAvoid duplicating “readonly” for each property by applying it to the interface definition itself. This is to reduce boilerplate code defining immutable objects.
Having interface where ALL properties are read only:
interface State {
readonly prop1: string;
readonly prop2: string;
...
readonly prop22: string;
}
equals to:
readonly interface State {
prop1: string;
prop2: string;
...
prop22: string;
}
Issue Analytics
- State:
- Created 6 years ago
- Reactions:22
- Comments:13 (8 by maintainers)
Top Results From Across the Web
Recommended to use Readonly against Interfaces?
Recommended to use Readonly against Interfaces? · It's simply a check to ensure that once the object is fully constructed, that field cannot...
Read more >Modifiable read-only Interface - CodeProject
Read-only interface is a simple thing. It does not allow the user to change its state. But sometimes, you may want to "change"...
Read more >Are readonly interfaces possible? : r/typescript - Reddit
I would suggest against using readonly on anything but arrays. It's very half-baked and, honestly, will probably lead to more bugs by providing ......
Read more >Making the interface form Read only!! - Appian Community
You can use parameter and make each form input read-only as suggested. Or you can create a second form with predefined read-only setting...
Read more >c# - How would I design an interface such that it's clear which ...
This interface has two read-only properties, Id and IsInvalidated . The fact that they are read-only, however, is by itself no guarantee that...
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
I think there might be value in extending this to cover a C++ like
const
behavior…I don’t have particularly strong feelings on the
const
versusreadonly
term here…const
is “nice” to me as it relates nicely to what this means in C++, which (some) people are used to.const interface
might be nice for deep readonly (kinda like{ a: { b: 1 } } as const
)