Ability to pick setter types (instead of getter types) in a mapped type #60162
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
typescript extract setter types mapped type
β Viability Checklist
β Suggestion
(original thread on Discord)
This might be a request for a new utility type, or a new language feature, because there seems to be no way to do it with current language features currently:
Given this type:
We want to derive a type like this:
There seems to be no way to implement
PickWithSetterTypes
in userland.π Motivating Example
When writing class-based JSX components (for example, custom elements are written as classes), the JSX property types are setters, not getters.
In this JSX expression:
The
foo
prop is asetter
, and it is setting the property on the custom element, it is not reading the property from the element.So, when we define a class component, for example:
We need to pluck the properties that we want available in the JSX. For example, something along the lines of this:
Now, the problem is, when we try to set a valid value for the property in JSX, it will not work:
There should not be a type error, because the setter actually does accept the value
'foo'
.π» Use Cases
The text was updated successfully, but these errors were encountered: