Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Issue:
This fixes the issue where spreading
actions('onChange', 'onSubmit')
into a component which requiresonChange
andonSubmit
props would still result in an error requesting those props be specified. I did not see an existing issue which describes this.What I did
This improves the
actions
type definition to return an object with the specific handler names provided. This is achieved via generic overloads.With this change, the return type of the above call would be
Record<'onChange' | 'onSubmit', ActionHandler>
and can fulfill required props.The overloads are a bit awkward because the trailing optional options param cannot follow a rest param.
How to test
Inspect the return type of calls to
actions
of the formactions('a', 'b', {})
,actions({ a: 'a', b: 'b' }, {})
, etc to ensure they return an object with specific keys rather than an indexed object. Alternatively, attempt to spread the return value ofactions
into e.g. a React component with required handler props.