facebook / prop-types

Runtime type checking for React props and similar objects
MIT License
4.48k stars 356 forks source link

Give developers the ability to create ".isRequired"-style type checker #170

Closed chengjianhua closed 5 years ago

chengjianhua commented 6 years ago

Feature Request:

All the type checkers of PropTypes are created by createChainableTypeChecker to create type checker with the chainable property isRequired.

Developers are also want to create the custom type checker keeps the same style of native type checkers provided by PropTypes and without the effort to repeat the work that prop-types have done. Okay, I know that we could do this ourselves, but if this will be provided, things are more easier and consistent.

So, It's feasible to export the createChainbleTypeChecker to developers ? BTW, may a shorter name.

alex-h-strachan commented 6 years ago

Agreed though I would suggest exporting a function named required() and just replacing the .isRequired syntax with required() going forward. Leave the other for compatibility, but

import { required, string } from 'prop-types';
const propTypes = { name: required(string), somethingCrazy: requried(somethingCrazy) }

is a lot more idiomatic IMO.

ljharb commented 5 years ago

Duplicate of #149.