New PropTypes.func that accepts argument/return configuration
- Dominant language
- JavaScript
- Stars
- 21
- Forks
- 6
- PR merge metrics
- No merged PRs in 30d
Description
Right now you can use `PropTypes.func` to describe a prop in `propTypes`, but for `index.d.ts` files generated for components this function really falls short.
I believe a more dynamic `PropTypes.func` would produce better documentation. It could be `PropTypes.function`.
For an example, `FormField` has a `doc.js` like this:
```js
DocumentedFormField.propTypes = {
validate: PropTypes.oneOfType([
PropTypes.shape({
regexp: PropTypes.object, // regular expression
message: PropTypes.string,
}),
PropTypes.func,
])
}
}
```
I believe with this new `PropTypes.function`, we could better describe the shape of the `validate` function as such:
```js
validate: PropTypes.oneOfType([
PropTypes.shape({
regexp: PropTypes.object, // regular expression
message: PropTypes.string,
}),
PropTypes.function(
PropTypes.string,
PropTypes.any,
).returns(PropTypes.oneOf([string, undefined]),
])
```
This would improve the `index.d.ts` produced by changing `validate`'s second type from
` ((...args: any[]) => any)`
to
`(arg1: string, arg2: any) => string | undefined`
I would find it interesting to work on this but not sure if the maintainers would support this. Please discuss this with me so I can learn if it's something you'd want!
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.