BVB Source Codes

prettier Show proptype_oneOf.js Source code

Return Download prettier: download proptype_oneOf.js Source code - Download prettier Source code - Type:.js
  1. /* @flow */
  2.  
  3. var React = require('react');
  4. var Example = React.createClass({
  5.   propTypes: {
  6.     str: React.PropTypes.oneOf(["foo", "bar"]),
  7.     num: React.PropTypes.oneOf([0, 1, 2]),
  8.     bool: React.PropTypes.oneOf([true]),
  9.     mixed: React.PropTypes.oneOf(["foo", 0, true]),
  10.   },
  11. });
  12.  
  13. (<Example str="foo" />); // OK
  14. (<Example str="baz" />); // error: 'baz' not in enum
  15.  
  16. (<Example num={0} />); // OK
  17. (<Example num={3} />); // error: 3 not in enum
  18.  
  19. (<Example bool={true} />); // OK
  20. (<Example bool={false} />); // error: false ~> true
  21.  
  22. (<Example mixed={"foo"} />); // OK
  23. (<Example mixed={0} />); // OK
  24. (<Example mixed={"baz"} />); // error: 'baz' not in enum
  25.  
  26. var RequiredExample = React.createClass({
  27.   propTypes: {
  28.     p: React.PropTypes.oneOf([]).isRequired,
  29.   },
  30. });
  31.  
  32. (<RequiredExample />); // error: `p` not found
  33.  
  34. var EmptyExample = React.createClass({
  35.   propTypes: {
  36.     nil: React.PropTypes.oneOf([]), // i.e., `empty`
  37.   },
  38. });
  39.  
  40. (<EmptyExample nil={0} />); // number ~> empty
  41.  
  42. var AnyArrayExample = React.createClass({
  43.   propTypes: {
  44.     any: React.PropTypes.oneOf((0:any)),
  45.   },
  46. });
  47.  
  48. (<AnyArrayExample any={0} />); // OK
  49.  
  50. var AnyElemExample = React.createClass({
  51.   propTypes: {
  52.     any: React.PropTypes.oneOf(["foo", (0:any)]),
  53.   },
  54. });
  55.  
  56. (<AnyElemExample any={0} />); // OK
  57.  
  58. var DynamicArrayExample = React.createClass({
  59.   propTypes: {
  60.     dyn: React.PropTypes.oneOf(([]: Array<string>)),
  61.   },
  62. });
  63.  
  64. (<DynamicArrayExample dyn={0} />); // OK
  65.  
  66. var DynamicElemExample = React.createClass({
  67.   propTypes: {
  68.     dyn: React.PropTypes.oneOf(["foo", ("": string)]),
  69.   },
  70. });
  71.  
  72. (<DynamicElemExample dyn={0} />); // OK
  73.  
  74. var InvalidArrayExample = React.createClass({
  75.   propTypes: {
  76.     p: React.PropTypes.oneOf(0), // error: expected array, got 0
  77.   },
  78. });
  79.  
  80. (<InvalidArrayExample p={0} />); // OK, don't cascade errors
  81.  
  82. var NonLiteralElemExample = React.createClass({
  83.   propTypes: {
  84.     p: React.PropTypes.oneOf([{}]), // OK: allow non-literals
  85.   },
  86. });
  87. (<NonLiteralElemExample p={0} />); // OK, result is unknown/any
  88.  
downloadproptype_oneOf.js Source code - Download prettier Source code
Related Source Codes/Software:
storybook - 2017-06-07
ionicons - The premium icon font for Ionic ... 2017-06-07
AsyncDisplayKit - Smooth asynchronous user interfaces for iOS apps. ... 2017-06-07
lottie-android - Render After Effects animations natively on Androi... 2017-06-07
parse-server - Parse-compatible API server module for Node/Expres... 2017-06-07
inferno - An extremely fast, React-like JavaScript library f... 2017-06-08
guetzli - Perceptual JPEG encoder 2017-06-08
cs-video-courses - List of Computer Science courses with video lectur... 2017-06-08
interviews - Everything you need to know to get the job. 2017-06-08
prepack - Prepack is a partial evaluator for JavaScript. Pre... 2017-06-08
CRYENGINE - CRYENGINE is a powerful real-time game development... 2017-06-11
postal - 2017-06-11
reactide - Reactide is the first dedicated IDE for React web ... 2017-06-11
rkt - rkt is a pod-native container engine for Linux. It... 2017-06-11
uWebSockets - Tiny WebSockets https://for... 2017-06-11
realworld - TodoMVC for the RealWorld - Exemplary fullstack Me... 2017-06-11
goreplay - GoReplay is an open-source tool for capturing and ... 2017-06-10
pyenv - Simple Python version management 2017-06-10
redux-saga - An alternative side effect model for Redux apps ... 2017-06-10
angular-starter - 2017-06-10

 Back to top