Skip to content

Instantly share code, notes, and snippets.

@eddyw
Last active February 5, 2018 06:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save eddyw/811247d35850ad5ce8228c4b03995919 to your computer and use it in GitHub Desktop.
Save eddyw/811247d35850ad5ce8228c4b03995919 to your computer and use it in GitHub Desktop.
Type-checking Redux State with propTypes (without React)
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',
)
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