Allow identifying readonly properties in mapped types #31581
Labels
Awaiting More Feedback
This means we'd like to hear from more people who would be helped by this feature
Suggestion
An idea for TypeScript
Search Terms
Pretty much the ones in the title...
Suggestion
Any TypeScript modifier should be allowed to be easily identified in mapped types. In particular,
readonly
should, but possibly others too, such as?
.Use Cases
Define mapped types where the values depend on whether the property is readonly or not. At the moment, the following madness is necessary for this:
I would like to see some syntactic sugar similar to (not intended to be a full implementation):
In my case, I would like to define a hyperscript-style function which accepts a series of attributes for the creation of HTML elements. For this, I reuse the interfaces that TypeScript defines, such as
HTMLAnchorElement
, but obviously readonly properties (among others) need to be excluded.Other people seem to have similar use cases, e.g. https://stackoverflow.com/questions/52443276/how-to-exclude-getter-only-properties-from-type-in-typescript
Checklist
My suggestion meets these guidelines:
The text was updated successfully, but these errors were encountered: