Skip to content

Commit 5e1e5e2

Browse files
MichaelBuessemeyerJoe FraleyqstearnsBrandon Dailaweary
authored
Update newest (#3)
* Include CI for master branch and PR's In accordance with facebook#19, includes config for TravisCI to run test reports on the master branch and PR's to the master branch. - Includes .travis.yml config file - Includes current CI status badge in README Closes facebook#19. * Point readme to correct docs for production builds (facebook#153) After an update to the docs, the production build was pointing to an outdated link. This commit directs the link to the appropriate location in the React docs. * 15.6.1 * Add 15.6.1 to CHANGELOG * Updated vars with consts and lets in PropTypesProductionReact15-test.js * Updated vars to consts and lets in PropTypesDevelopmentReact15.js * Updated vars to consts and lets in PropTypesDevelopmentStandalone-test.js * Updated vars to consts and lets in PropTypesProductionStandalone-test.js * Add example for `PropTypes.exact` * Show that shapes can have required properties * Move explanation of `isRequired` and show it in `PropTypes.shape` * Remove trailing spaces * Remove fbjs dependency * Preserve "Invariant Violation" name * 15.6.2 * .com * Add support for objects with a null prototype in objectOf * Replace `hasOwnProperty` with the more robust "has" package * Revert "Replace `hasOwnProperty` with the more robust "has" package" This reverts commit e6a9b28. * Inline the `has` module * missed semicolon * [Tests] use componentName in getPropTypeWarningMessage instead of hard-coded testComponent * [Fix] Fix `oneOf` when used with Symbols - Fixes error due to an attempt to coerce a Symbol to a string - Improves formatting of the "expected" portion of the generated warning, outputting for example `["Symbol(A)","Symbol(B)"]` rather than `[null,null]` Fixes facebook#10 * Completely remove envify in favor of loose-envify Closes facebook#203. * [New] Add `.elementType` * Add license to readme * [Fix] Support validation when hasOwnProperty is not in prototype Closes facebook#183; relates to facebook#112. * [Docs] fix relative release date to be absolute * [Docs] Fix typo in example * [New] add `PropTypes.resetWarningCache` * [dev deps] update `loose-envify` * `oneOf`: improve warning when multiple arguments are supplied Adds a different warning message for multiple arguments supplied to oneOf. A common mistake is to write oneOf(x, y, z) instead of oneOf([x, y, z]) and this should help developers identifying the error. * [changelog] update repo links * v15.7.0 * [Fix] avoid template literal syntax Fixes facebook#255. Fixes facebook#254. * v15.7.1 * [Tests] add `eslint`; run more travis tests * [Tests] run tests with multiple react versions * [Fix] move `loose-envify` back to production deps, for browerify usage Fixes facebook#203 * [Tests] add additional passing tests * [Fix] ensure nullish values in `oneOf` do not crash Fixes facebook#256. * [dev deps] update `browserify` * v15.7.2 * [Docs] Improve wording for `checkPropTypes` * [Docs] `PropTypes.node`: add link to react docs Fixes facebook#154. * [meta] use `in-publish` to avoid running the build on install * `checkPropTypes`: Friendlier message when using a type checker that is not a function * [Tests] test the build process * [New] Add type check for validator for 'shape' and 'exact' Fixes facebook#220. * [Tests] fix broken tests * [Refactor] extract `has` * [Docs] Add instructions for intentional inclusion of validation in production. * [New] `oneOfType`: Add expected types to warning Adds data object to returned error in checker so that the expected types can be accessed from within oneOfType check. Also, updates the tests slightly. Fixes facebook#9. * [Tests] Fixed typo: 'Any type *should* accept any value' * [Dev Deps] update `eslint` * [Deps] update `react-is` * [Dev Deps] update `browserify`, `bundle-collapser`, `react`, `uglifyify`, `uglifyjs` * [Docs] Typo fix in example Reverts an incorrect typo fix made in facebook#248. Closes facebook#299 * [Tests] Fix spelling * doc: highlighted the func name (facebook#321) * [readme] Clarify usage of `elementType` Closes facebook#334. * [Dev Deps] update `bundle-collapser`, `eslint`, `in-publish`, `react` * [Deps] update `react-is` * Add a package `sideEffects` field. * Bump sshpk from 1.13.1 to 1.16.1 Bumps [sshpk](https://github.com/joyent/node-sshpk) from 1.13.1 to 1.16.1. - [Release notes](https://github.com/joyent/node-sshpk/releases) - [Commits](TritonDataCenter/node-sshpk@v1.13.1...v1.16.1) Signed-off-by: dependabot[bot] <[email protected]> * Use GH Actions This migrates to a more accessible platform * [eslint] enable some rules Additional ESLint rules: "no-multi-spaces": ["error"], "key-spacing": ["error"] "no-multi-spaces" - Disallow multiple spaces; "key-spacing" - Enforce consistent spacing between keys and values in object literal properties; * Bump path-parse from 1.0.6 to 1.0.7 Bumps [path-parse](https://github.com/jbgutierrez/path-parse) from 1.0.6 to 1.0.7. - [Release notes](https://github.com/jbgutierrez/path-parse/releases) - [Commits](https://github.com/jbgutierrez/path-parse/commits/v1.0.7) --- updated-dependencies: - dependency-name: path-parse dependency-type: indirect ... Signed-off-by: dependabot[bot] <[email protected]> * Bump tmpl from 1.0.4 to 1.0.5 Bumps [tmpl](https://github.com/daaku/nodejs-tmpl) from 1.0.4 to 1.0.5. - [Release notes](https://github.com/daaku/nodejs-tmpl/releases) - [Commits](https://github.com/daaku/nodejs-tmpl/commits/v1.0.5) --- updated-dependencies: - dependency-name: tmpl dependency-type: indirect ... Signed-off-by: dependabot[bot] <[email protected]> * [deps] regenerate yarn.lock * [readme] Fix branch name (master -> main) * [Dev Deps] update `eslint` * [New] add `PropTypes.bigint` Closes facebook#355 * v15.8.0 * [Tests] do not fail fast; add react 17 * [meta] Fix formatting in CHANGELOG.md * [Tests] convert normal `it` functions to arrow functions * [Tests] add missing test coverage * [Fix] fix crash when a custom propType return lacks `.data`; call `hasOwnProperty` properly Fixes facebook#369 * [Dev Deps] update `eslint` * v15.8.1 * docs: add GH button in support of Ukraine (facebook#375) ## Summary Our mission at Meta Open Source is to empower communities through open source, and we believe that it means building a welcoming and safe environment for all. As a part of this work, we are adding this banner in support for Ukraine during this crisis. * [Deps] `yarn upgrade` * build: harden ci.yml permissions Signed-off-by: Alex <[email protected]> * Bump semver from 5.7.1 to 5.7.2 Bumps [semver](https://github.com/npm/node-semver) from 5.7.1 to 5.7.2. - [Release notes](https://github.com/npm/node-semver/releases) - [Changelog](https://github.com/npm/node-semver/blob/v5.7.2/CHANGELOG.md) - [Commits](npm/node-semver@v5.7.1...v5.7.2) --- updated-dependencies: - dependency-name: semver dependency-type: indirect ... Signed-off-by: dependabot[bot] <[email protected]> * Bump ua-parser-js from 0.7.32 to 0.7.33 Bumps [ua-parser-js](https://github.com/faisalman/ua-parser-js) from 0.7.32 to 0.7.33. - [Release notes](https://github.com/faisalman/ua-parser-js/releases) - [Changelog](https://github.com/faisalman/ua-parser-js/blob/master/changelog.md) - [Commits](faisalman/ua-parser-js@0.7.32...0.7.33) --- updated-dependencies: - dependency-name: ua-parser-js dependency-type: indirect ... Signed-off-by: dependabot[bot] <[email protected]> * remove production env tests as we do not have any production env tests * update --------- Signed-off-by: dependabot[bot] <[email protected]> Signed-off-by: Alex <[email protected]> Co-authored-by: Joe Fraley <[email protected]> Co-authored-by: Quinn Stearns <[email protected]> Co-authored-by: Brandon Dail <[email protected]> Co-authored-by: Brandon Dail <[email protected]> Co-authored-by: Barry <[email protected]> Co-authored-by: Christian Paul <[email protected]> Co-authored-by: Dan Abramov <[email protected]> Co-authored-by: Julien Mourer <[email protected]> Co-authored-by: ksmolniy <[email protected]> Co-authored-by: C. T. Lin <[email protected]> Co-authored-by: Jim Fitzpatrick <[email protected]> Co-authored-by: Augustin Trancart <[email protected]> Co-authored-by: Benoit Tremblay <[email protected]> Co-authored-by: Dominik Ferber <[email protected]> Co-authored-by: Joseph A. Szczesniak <[email protected]> Co-authored-by: Troy Rhinehart <[email protected]> Co-authored-by: Patrick Way <[email protected]> Co-authored-by: Jordan Harband <[email protected]> Co-authored-by: Wojciech Maj <[email protected]> Co-authored-by: NoScripter <[email protected]> Co-authored-by: Gregory Desfour <[email protected]> Co-authored-by: Asbjørn Hegdahl <[email protected]> Co-authored-by: NoScripter <[email protected]> Co-authored-by: rgraffbrd <[email protected]> Co-authored-by: Josh Alling <[email protected]> Co-authored-by: weiluntong <[email protected]> Co-authored-by: Conrad Buck <[email protected]> Co-authored-by: Mark McCann <[email protected]> Co-authored-by: John Bampton <[email protected]> Co-authored-by: Haseeb Khan <[email protected]> Co-authored-by: G Roques <[email protected]> Co-authored-by: Jayden Seric <[email protected]> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Paul O’Shannessy <[email protected]> Co-authored-by: Konstantin Popov <[email protected]> Co-authored-by: Dmitry Vinnik <[email protected]> Co-authored-by: Alex <[email protected]>
1 parent e66fc8c commit 5e1e5e2

17 files changed

+3116
-2518
lines changed

.eslintignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
prop-types.min.js

.eslintrc

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
{
2+
"root": true,
3+
"parserOptions": {
4+
"ecmaVersion": 5,
5+
},
6+
"env": {
7+
"browser": true,
8+
"node": true,
9+
},
10+
"rules": {
11+
"no-console": "off",
12+
"no-multi-spaces": ["error"],
13+
"key-spacing": ["error"],
14+
},
15+
"overrides": [
16+
{
17+
"files": "**/__tests__/**/*",
18+
"env": {
19+
"jest": true,
20+
"jasmine": true,
21+
"es6": true,
22+
},
23+
"rules": {
24+
"no-unused-vars": "off",
25+
},
26+
"parserOptions": {
27+
"ecmaVersion": 2019,
28+
"ecmaFeatures": {
29+
"jsx": true,
30+
},
31+
},
32+
},
33+
],
34+
}

.github/workflows/ci.yml

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
name: CI
2+
on:
3+
- push
4+
- pull_request
5+
6+
permissions:
7+
contents: read # to fetch code (actions/checkout)
8+
9+
jobs:
10+
ci:
11+
name: "Build & Test (React v${{ matrix.react_version}})"
12+
runs-on: ubuntu-latest
13+
strategy:
14+
fail-fast: false
15+
matrix:
16+
react_version:
17+
- "17"
18+
- "16"
19+
- "16.0"
20+
- "15"
21+
- "15.0"
22+
- "0.14.9"
23+
steps:
24+
- uses: actions/checkout@v2
25+
- uses: actions/setup-node@v2
26+
with:
27+
node-version: "lts/*"
28+
cache: 'yarn'
29+
- run: yarn install
30+
- run: yarn add react@${{ matrix.react_version }}
31+
- run: yarn list --pattern 'react'
32+
- run: yarn run pretest
33+
- run: yarn run tests-only
34+
- run: yarn run build

CHANGELOG.md

Lines changed: 67 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,56 +1,110 @@
1+
## 15.8.1
2+
* [Fix] fix crash when a custom propType return lacks `.data`; call `hasOwnProperty` properly (#370)
3+
* [meta] Fix formatting in CHANGELOG.md (#367)
4+
* [Tests] add missing test coverage (#370)
5+
* [Tests] convert normal `it` functions to arrow functions (#370)
6+
* [Tests] do not fail fast; add react 17 (#366)
7+
* [Dev Deps] update `eslint`
8+
9+
## 15.8.0
10+
* [New] add `PropTypes.bigint` (#365)
11+
* [New] `oneOfType`: Add expected types to warning (#198)
12+
* [New] Add type check for validator for 'shape' and 'exact' (#234)
13+
* [Fix] `checkPropTypes`: Friendlier message when using a type checker that is not a function (#51)
14+
* [Refactor] extract `has` (#261, #125, #124)
15+
* [readme] Fix branch name (master -> main) (#364)
16+
* [readme] Clarify usage of `elementType` (#335)
17+
* [docs] highlighted the func name (#321)
18+
* [docs] Typo fix in example (#300)
19+
* [docs] Add instructions for intentional inclusion of validation in production. (#262)
20+
* [docs] `PropTypes.node`: add link to react docs
21+
* [docs] Improve wording for `checkPropTypes` (#258)
22+
* [meta] Add a package `sideEffects` field. (#350)
23+
* [meta] use `in-publish` to avoid running the build on install
24+
* [deps] regenerate yarn.lock
25+
* [deps] update `react-is` (#347, #346, #345, #340, #338)
26+
* [eslint] enable some rules (#360)
27+
* [Tests] Use GH Actions (#363)
28+
* [Tests] Fix spelling (#318)
29+
* [Tests] Fixed typo: 'Any type *should* accept any value' (#281)
30+
* [Tests] fix broken tests; test the build process
31+
* [Dev Deps] update `browserify`, `bundle-collapser`, `eslint`, `in-publish`, `react`, `uglifyify`, `uglifyjs`
32+
33+
## 15.7.2
34+
* [Fix] ensure nullish values in `oneOf` do not crash ([#256](https://github.com/facebook/prop-types/issues/256))
35+
* [Fix] move `loose-envify` back to production deps, for browerify usage ([#203](https://github.com/facebook/prop-types/issues/203))
36+
37+
## 15.7.1
38+
* [Fix] avoid template literal syntax ([#255](https://github.com/facebook/prop-types/issues/255), [#254](https://github.com/facebook/prop-types/issues/254))
39+
40+
## 15.7.0
41+
* [New] Add `.elementType` ([#211](https://github.com/facebook/prop-types/pull/211))
42+
* [New] add `PropTypes.resetWarningCache` ([#178](https://github.com/facebook/prop-types/pull/178))
43+
* `oneOf`: improve warning when multiple arguments are supplied ([#244](https://github.com/facebook/prop-types/pull/244))
44+
* Fix `oneOf` when used with Symbols ([#224](https://github.com/facebook/prop-types/pull/224))
45+
* Avoid relying on `hasOwnProperty` being present on values' prototypes ([#112](https://github.com/facebook/prop-types/pull/112), [#187](https://github.com/facebook/prop-types/pull/187))
46+
* Improve readme ([#248](https://github.com/facebook/prop-types/pull/248), [#233](https://github.com/facebook/prop-types/pull/233))
47+
* Clean up mistaken runtime dep, swap envify for loose-envify ([#204](https://github.com/facebook/prop-types/pull/204))
48+
49+
## 15.6.2
50+
* Remove the `fbjs` dependency by inlining some helpers from it ([#194](https://github.com/facebook/prop-types/pull/194)))
51+
52+
## 15.6.1
53+
* Fix an issue where outdated BSD license headers were still present in the published bundle [#162](https://github.com/facebook/prop-types/issues/162)
54+
155
## 15.6.0
256

357
* Switch from BSD + Patents to MIT license
4-
* Add PropTypes.exact, like PropTypes.shape but warns on extra object keys. ([@thejameskyle](https://github.com/thejameskyle) and [@aweary](https://github.com/aweary) in [#41](https://github.com/reactjs/prop-types/pull/41) and [#87](https://github.com/reactjs/prop-types/pull/87))
58+
* Add PropTypes.exact, like PropTypes.shape but warns on extra object keys. ([@thejameskyle](https://github.com/thejameskyle) and [@aweary](https://github.com/aweary) in [#41](https://github.com/facebook/prop-types/pull/41) and [#87](https://github.com/facebook/prop-types/pull/87))
559

660
## 15.5.10
761

8-
* Fix a false positive warning when using a production UMD build of a third-party library with a DEV version of React. ([@gaearon](https://github.com/gaearon) in [#50](https://github.com/reactjs/prop-types/pull/50))
62+
* Fix a false positive warning when using a production UMD build of a third-party library with a DEV version of React. ([@gaearon](https://github.com/gaearon) in [#50](https://github.com/facebook/prop-types/pull/50))
963

1064
## 15.5.9
1165

12-
* Add `loose-envify` Browserify transform for users who don't envify globally. ([@mridgway](https://github.com/mridgway) in [#45](https://github.com/reactjs/prop-types/pull/45))
66+
* Add `loose-envify` Browserify transform for users who don't envify globally. ([@mridgway](https://github.com/mridgway) in [#45](https://github.com/facebook/prop-types/pull/45))
1367

1468
## 15.5.8
1569

16-
* Limit the manual PropTypes call warning count because it has false positives with React versions earlier than 15.2.0 in the 15.x branch and 0.14.9 in the 0.14.x branch. ([@gaearon](https://github.com/gaearon) in [#26](https://github.com/reactjs/prop-types/pull/26))
70+
* Limit the manual PropTypes call warning count because it has false positives with React versions earlier than 15.2.0 in the 15.x branch and 0.14.9 in the 0.14.x branch. ([@gaearon](https://github.com/gaearon) in [#26](https://github.com/facebook/prop-types/pull/26))
1771

1872
## 15.5.7
1973

20-
* **Critical Bugfix:** Fix an accidental breaking change that caused errors in production when used through `React.PropTypes`. ([@gaearon](https://github.com/gaearon) in [#20](https://github.com/reactjs/prop-types/pull/20))
21-
* Improve the size of production UMD build. ([@aweary](https://github.com/aweary) in [38ba18](https://github.com/reactjs/prop-types/commit/38ba18a4a8f705f4b2b33c88204573ddd604f2d6) and [7882a7](https://github.com/reactjs/prop-types/commit/7882a7285293db5f284bcf559b869fd2cd4c44d4))
74+
* **Critical Bugfix:** Fix an accidental breaking change that caused errors in production when used through `React.PropTypes`. ([@gaearon](https://github.com/gaearon) in [#20](https://github.com/facebook/prop-types/pull/20))
75+
* Improve the size of production UMD build. ([@aweary](https://github.com/aweary) in [38ba18](https://github.com/facebook/prop-types/commit/38ba18a4a8f705f4b2b33c88204573ddd604f2d6) and [7882a7](https://github.com/facebook/prop-types/commit/7882a7285293db5f284bcf559b869fd2cd4c44d4))
2276

2377
## 15.5.6
2478

2579
**Note: this release has a critical issue and was deprecated. Please update to 15.5.7 or higher.**
2680

27-
* Fix a markdown issue in README. ([@bvaughn](https://github.com/bvaughn) in [174f77](https://github.com/reactjs/prop-types/commit/174f77a50484fa628593e84b871fb40eed78b69a))
81+
* Fix a markdown issue in README. ([@bvaughn](https://github.com/bvaughn) in [174f77](https://github.com/facebook/prop-types/commit/174f77a50484fa628593e84b871fb40eed78b69a))
2882

2983
## 15.5.5
3084

3185
**Note: this release has a critical issue and was deprecated. Please update to 15.5.7 or higher.**
3286

33-
* Add missing documentation and license files. ([@bvaughn](https://github.com/bvaughn) in [0a53d3](https://github.com/reactjs/prop-types/commit/0a53d3a34283ae1e2d3aa396632b6dc2a2061e6a))
87+
* Add missing documentation and license files. ([@bvaughn](https://github.com/bvaughn) in [0a53d3](https://github.com/facebook/prop-types/commit/0a53d3a34283ae1e2d3aa396632b6dc2a2061e6a))
3488

3589
## 15.5.4
3690

3791
**Note: this release has a critical issue and was deprecated. Please update to 15.5.7 or higher.**
3892

39-
* Reduce the size of the UMD Build. ([@acdlite](https://github.com/acdlite) in [31e9344](https://github.com/reactjs/prop-types/commit/31e9344ca3233159928da66295da17dad82db1a8))
40-
* Remove bad package url. ([@ljharb](https://github.com/ljharb) in [158198f](https://github.com/reactjs/prop-types/commit/158198fd6c468a3f6f742e0e355e622b3914048a))
93+
* Reduce the size of the UMD Build. ([@acdlite](https://github.com/acdlite) in [31e9344](https://github.com/facebook/prop-types/commit/31e9344ca3233159928da66295da17dad82db1a8))
94+
* Remove bad package url. ([@ljharb](https://github.com/ljharb) in [158198f](https://github.com/facebook/prop-types/commit/158198fd6c468a3f6f742e0e355e622b3914048a))
4195
* Remove the accidentally included typechecking code from the production build.
4296

4397
## 15.5.3
4498

4599
**Note: this release has a critical issue and was deprecated. Please update to 15.5.7 or higher.**
46100

47-
* Remove the accidentally included React package code from the UMD bundle. ([@acdlite](https://github.com/acdlite) in [df318bb](https://github.com/reactjs/prop-types/commit/df318bba8a89bc5aadbb0292822cf4ed71d27ace))
101+
* Remove the accidentally included React package code from the UMD bundle. ([@acdlite](https://github.com/acdlite) in [df318bb](https://github.com/facebook/prop-types/commit/df318bba8a89bc5aadbb0292822cf4ed71d27ace))
48102

49103
## 15.5.2
50104

51105
**Note: this release has a critical issue and was deprecated. Please update to 15.5.7 or higher.**
52106

53-
* Remove dependency on React for CommonJS entry point. ([@acdlite](https://github.com/acdlite) in [cae72bb](https://github.com/reactjs/prop-types/commit/cae72bb281a3766c765e3624f6088c3713567e6d))
107+
* Remove dependency on React for CommonJS entry point. ([@acdlite](https://github.com/acdlite) in [cae72bb](https://github.com/facebook/prop-types/commit/cae72bb281a3766c765e3624f6088c3713567e6d))
54108

55109

56110
## 15.5.1
@@ -67,4 +121,4 @@
67121

68122
## Before 15.5.0
69123

70-
PropTypes was previously included in React, but is now a separate package. For earlier history of PropTypes [see the React change log.](https://github.com/facebook/react/blob/master/CHANGELOG.md)
124+
PropTypes was previously included in React, but is now a separate package. For earlier history of PropTypes [see the React change log.](https://github.com/facebook/react/blob/HEAD/CHANGELOG.md)

CONTRIBUTING.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ The code of conduct is described in [`CODE_OF_CONDUCT.md`](CODE_OF_CONDUCT.md).
88
## Pull Requests
99
We actively welcome your pull requests.
1010

11-
1. Fork the repo and create your branch from `master`.
11+
1. Fork the repo and create your branch from `main`.
1212
2. If you've added code that should be tested, add tests.
1313
3. If you've changed APIs, update the documentation.
1414
4. Ensure the test suite passes.

README.md

Lines changed: 39 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
# prop-types
1+
# prop-types [![Support Ukraine](https://img.shields.io/badge/Support-Ukraine-FFD500?style=flat&labelColor=005BBB)](https://opensource.fb.com/support-ukraine) [![Build Status](https://travis-ci.com/facebook/prop-types.svg?branch=main)](https://travis-ci.org/facebook/prop-types)
22

33
Runtime type checking for React props and similar objects.
44

55
You can use prop-types to document the intended types of properties passed to
6-
components. React (and potentially other libraries—see the checkPropTypes()
6+
components. React (and potentially other libraries—see the `checkPropTypes()`
77
reference below) will check props passed to your components against those
88
definitions, and warn in development if they don’t match.
99

@@ -22,8 +22,8 @@ var PropTypes = require('prop-types'); // ES5 with npm
2222

2323
### CDN
2424

25-
If you prefer to exclude `prop-types` from your application and use it
26-
globally via `window.PropTypes`, the `prop-types` package provides
25+
If you prefer to exclude `prop-types` from your application and use it
26+
globally via `window.PropTypes`, the `prop-types` package provides
2727
single-file distributions, which are hosted on the following CDNs:
2828

2929
* [**unpkg**](https://unpkg.com/prop-types/)
@@ -44,7 +44,7 @@ single-file distributions, which are hosted on the following CDNs:
4444
<script src="https://cdnjs.cloudflare.com/ajax/libs/prop-types/15.6.0/prop-types.min.js"></script>
4545
```
4646

47-
To load a specific version of `prop-types` replace `15.6.0` with the version number.
47+
To load a specific version of `prop-types` replace `15.6.0` with the version number.
4848

4949
## Usage
5050

@@ -67,6 +67,7 @@ MyComponent.propTypes = {
6767
// You can declare that a prop is a specific JS primitive. By default, these
6868
// are all optional.
6969
optionalArray: PropTypes.array,
70+
optionalBigInt: PropTypes.bigint,
7071
optionalBool: PropTypes.bool,
7172
optionalFunc: PropTypes.func,
7273
optionalNumber: PropTypes.number,
@@ -76,11 +77,17 @@ MyComponent.propTypes = {
7677

7778
// Anything that can be rendered: numbers, strings, elements or an array
7879
// (or fragment) containing these types.
80+
// see https://reactjs.org/docs/rendering-elements.html for more info
7981
optionalNode: PropTypes.node,
8082

81-
// A React element.
83+
// A React element (ie. <MyComponent />).
8284
optionalElement: PropTypes.element,
8385

86+
// A React element type (eg. MyComponent).
87+
// a function, string, or "element-like" object (eg. React.Fragment, Suspense, etc.)
88+
// see https://github.com/facebook/react/blob/HEAD/packages/shared/isValidElementType.js
89+
optionalElementType: PropTypes.elementType,
90+
8491
// You can also declare that a prop is an instance of a class. This uses
8592
// JS's instanceof operator.
8693
optionalMessage: PropTypes.instanceOf(Message),
@@ -102,14 +109,21 @@ MyComponent.propTypes = {
102109
// An object with property values of a certain type
103110
optionalObjectOf: PropTypes.objectOf(PropTypes.number),
104111

112+
// You can chain any of the above with `isRequired` to make sure a warning
113+
// is shown if the prop isn't provided.
114+
105115
// An object taking on a particular shape
106116
optionalObjectWithShape: PropTypes.shape({
107-
color: PropTypes.string,
108-
fontSize: PropTypes.number
117+
optionalProperty: PropTypes.string,
118+
requiredProperty: PropTypes.number.isRequired
119+
}),
120+
121+
// An object with warnings on extra properties
122+
optionalObjectWithStrictShape: PropTypes.exact({
123+
optionalProperty: PropTypes.string,
124+
requiredProperty: PropTypes.number.isRequired
109125
}),
110126

111-
// You can chain any of the above with `isRequired` to make sure a warning
112-
// is shown if the prop isn't provided.
113127
requiredFunc: PropTypes.func.isRequired,
114128

115129
// A value of any data type
@@ -160,18 +174,18 @@ For example:
160174

161175
```js
162176
"dependencies": {
163-
"prop-types": "^15.5.7"
177+
"prop-types": "^15.5.7"
164178
}
165179
```
166180

167181
For libraries, we *also* recommend leaving it in `dependencies`:
168182

169183
```js
170184
"dependencies": {
171-
"prop-types": "^15.5.7"
185+
"prop-types": "^15.5.7"
172186
},
173187
"peerDependencies": {
174-
"react": "^15.5.0"
188+
"react": "^15.5.0"
175189
}
176190
```
177191

@@ -185,7 +199,7 @@ For UMD bundles of your components, make sure you **don’t** include `PropTypes
185199

186200
### React 0.14
187201

188-
This package is compatible with **React 0.14.9**. Compared to 0.14.8 (which was released a year ago), there are no other changes in 0.14.9, so it should be a painless upgrade.
202+
This package is compatible with **React 0.14.9**. Compared to 0.14.8 (which was released in March of 2016), there are no other changes in 0.14.9, so it should be a painless upgrade.
189203

190204
```shell
191205
# ATTENTION: Only run this if you still use React 0.14!
@@ -246,9 +260,11 @@ PropTypes.checkPropTypes(MyComponent.propTypes, props, 'prop', 'MyComponent');
246260
```
247261
See below for more info.
248262

263+
**If you DO want to use validation in production**, you can choose to use the **development version** by importing/requiring `prop-types/prop-types` instead of `prop-types`.
264+
249265
**You might also see this error** if you’re calling a `PropTypes` validator from your own custom `PropTypes` validator. In this case, the fix is to make sure that you are passing *all* of the arguments to the inner function. There is a more in-depth explanation of how to fix it [on this page](https://facebook.github.io/react/warnings/dont-call-proptypes.html#fixing-the-false-positive-in-third-party-proptypes). Alternatively, you can temporarily keep using `React.PropTypes` until React 16, as it would still only warn in this case.
250266

251-
If you use a bundler like Browserify or Webpack, don’t forget to [follow these instructions](https://facebook.github.io/react/docs/installation.html#development-and-production-versions) to correctly bundle your application in development or production mode. Otherwise you’ll ship unnecessary code to your users.
267+
If you use a bundler like Browserify or Webpack, don’t forget to [follow these instructions](https://reactjs.org/docs/optimizing-performance.html#use-the-production-build) to correctly bundle your application in development or production mode. Otherwise you’ll ship unnecessary code to your users.
252268

253269
## PropTypes.checkPropTypes
254270

@@ -276,3 +292,11 @@ PropTypes.checkPropTypes(myPropTypes, props, 'prop', 'MyComponent');
276292
// Warning: Failed prop type: Invalid prop `age` of type `string` supplied to
277293
// `MyComponent`, expected `number`.
278294
```
295+
296+
## PropTypes.resetWarningCache()
297+
298+
`PropTypes.checkPropTypes(...)` only `console.error`s a given message once. To reset the error warning cache in tests, call `PropTypes.resetWarningCache()`
299+
300+
### License
301+
302+
prop-types is [MIT licensed](./LICENSE).

0 commit comments

Comments
 (0)