Last active
February 5, 2018 06:32
-
-
Save eddyw/811247d35850ad5ce8228c4b03995919 to your computer and use it in GitHub Desktop.
Type-checking Redux State with propTypes (without React)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import propTypes from 'prop-types' | |
const pTypes = { | |
name: propTypes.string.isRequired, | |
age: propTypes.number.isRequired, | |
} | |
const obj = { | |
name: 16, | |
age: 'John', | |
} | |
propTypes.checkPropTypes( | |
pTypes, | |
obj, | |
'property', | |
'obj', | |
) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Outputs in console: | |
Warning: Failed property type: Invalid property `age` of type `string` | |
supplied to `obj`, expected `number`. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment