Skip to content

Commit

Permalink
Add propType check with validation (vercel#2516)
Browse files Browse the repository at this point in the history
  • Loading branch information
timneutkens authored and arunoda committed Jul 9, 2017
1 parent 5a0c61a commit ee29abb
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 3 deletions.
6 changes: 6 additions & 0 deletions lib/error.js
Original file line number Diff line number Diff line change
@@ -1,4 1,6 @@
import React from 'react'
import PropTypes from 'prop-types'
import exact from 'prop-types-exact'
import HTTPStatus from 'http-status'
import Head from './head'

Expand All @@ -8,6 10,10 @@ export default class Error extends React.Component {
return { statusCode }
}

static propTypes = exact({
statusCode: PropTypes.number
})

render () {
const { statusCode } = this.props
const title = statusCode === 404
Expand Down
6 changes: 4 additions & 2 deletions lib/link.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 3,7 @@
import { resolve, format, parse } from 'url'
import React, { Component, Children } from 'react'
import PropTypes from 'prop-types'
import exact from 'prop-types-exact'
import Router, { _rewriteUrlForNextExport } from './router'
import { warn, execOnce, getLocationOrigin } from './utils'

Expand All @@ -13,7 14,8 @@ export default class Link extends Component {
this.formatUrls(props)
}

static propTypes = {
static propTypes = exact({
href: PropTypes.string,
prefetch: PropTypes.bool,
children: PropTypes.oneOfType([
PropTypes.element,
Expand All @@ -29,7 31,7 @@ export default class Link extends Component {
]).isRequired,
shallow: PropTypes.bool,
passHref: PropTypes.bool
}
})

componentWillReceiveProps (nextProps) {
this.formatUrls(nextProps)
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 83,7 @@
"path-match": "1.2.4",
"pkg-up": "2.0.0",
"prop-types": "15.5.10",
"prop-types-exact": "^1.1.1",
"react-hot-loader": "3.0.0-beta.7",
"recursive-copy": "^2.0.6",
"send": "^0.15.3",
Expand Down
17 changes: 16 additions & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4003,10 4003,18 @@ object-assign@^4.0.1, object-assign@^4.1.0:
version "4.1.1"
resolved "https://registry.yarnpkg.com/object-assign/-/object-assign-4.1.1.tgz#2109adc7965887cfc05cbbd442cac8bfbb360863"

object-keys@^1.0.8:
object-keys@^1.0.10, object-keys@^1.0.8:
version "1.0.11"
resolved "https://registry.yarnpkg.com/object-keys/-/object-keys-1.0.11.tgz#c54601778ad560f1142ce0e01bcca8b56d13426d"

object.assign@^4.0.4:
version "4.0.4"
resolved "https://registry.yarnpkg.com/object.assign/-/object.assign-4.0.4.tgz#b1c9cc044ef1b9fe63606fc141abbb32e14730cc"
dependencies:
define-properties "^1.1.2"
function-bind "^1.1.0"
object-keys "^1.0.10"

object.omit@^2.0.0:
version "2.0.1"
resolved "https://registry.yarnpkg.com/object.omit/-/object.omit-2.0.1.tgz#1a9c744829f39dbb858c76ca3579ae2a54ebd1fa"
Expand Down Expand Up @@ -4324,6 4332,13 @@ promise@^7.0.1, promise@^7.1.1:
dependencies:
asap "~2.0.3"

prop-types-exact@^1.1.1:
version "1.1.1"
resolved "https://registry.yarnpkg.com/prop-types-exact/-/prop-types-exact-1.1.1.tgz#c2620207e4f77f9762fa1835b0387a464bd08978"
dependencies:
has "^1.0.1"
object.assign "^4.0.4"

[email protected], prop-types@^15.5.4, prop-types@^15.5.7, prop-types@~15.5.7:
version "15.5.10"
resolved "https://registry.yarnpkg.com/prop-types/-/prop-types-15.5.10.tgz#2797dfc3126182e3a95e3dfbb2e893ddd7456154"
Expand Down

0 comments on commit ee29abb

Please sign in to comment.