{"id":18552461,"url":"https://github.com/andrejewski/react-types","last_synced_at":"2025-04-09T22:31:56.319Z","repository":{"id":34555444,"uuid":"38500644","full_name":"andrejewski/react-types","owner":"andrejewski","description":"React.PropTypes with less suck","archived":false,"fork":false,"pushed_at":"2015-07-09T14:14:09.000Z","size":132,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-05T00:02:39.999Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"isc","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/andrejewski.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-07-03T16:02:28.000Z","updated_at":"2019-03-28T16:38:11.000Z","dependencies_parsed_at":"2022-09-08T15:00:45.953Z","dependency_job_id":null,"html_url":"https://github.com/andrejewski/react-types","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/andrejewski%2Freact-types","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/andrejewski%2Freact-types/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/andrejewski%2Freact-types/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/andrejewski%2Freact-types/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/andrejewski","download_url":"https://codeload.github.com/andrejewski/react-types/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247994135,"owners_count":21030051,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-06T21:14:17.974Z","updated_at":"2025-04-09T22:31:55.746Z","avatar_url":"https://github.com/andrejewski.png","language":"JavaScript","readme":"# React Types\n\nI don't like React's PropTypes, but I do like prop validation. React Types replaces the verbosity of PropTypes with something more like how [Mongoose](https://github.com/Automattic/mongoose) does its [schema building](http://mongoosejs.com/docs/schematypes.html).\n\n```bash\nnpm install react-types\n```\n\n## What does it do?\n\nInstead of this:\n\n```js\nvar MyComponent = React.createClass({\n  propTypes: {\n    name: React.PropTypes.string.isRequired,\n    isKewl: React.PropTypes.bool.isRequired,\n    cats: React.PropTypes.arrayOf(React.PropsTypes.shape({\n      name: React.PropTypes.string.isRequired,\n      age: React.PropTypes.number.isRequired\n    }))\n  }\n});\n// holy crap, glad I don't ever have to write that again...\n```\n\nYou can write this:\n\n```js\nvar types = require('react-types');\nvar Shape = types.Shape;\n\nMyComponent = React.createClass({\n  propTypes: types({\n    name: String,\n    isKewl: Boolean,\n    cats: [Shape({\n      name: String,\n      age: Number\n    })]\n  })\n});\n```\n\nThere is a more feature-packed [comparison](https://github.com/andrejewski/react-types/blob/master/comparison.js) available to see how everything stacks up against regular PropTypes.\n\nBut of course it's your choice which you would prefer to type.\n\n## FAQ\n\n### Prop types: optional versus required?\n\nReact makes all propTypes optional by default, which I think is a bad choice. Props are going to be passed to the component whether or not they are specified so everything is optional by default. If I go to the trouble of writing out the propType for a member, it better dam be there. \n\nSo, React Types are required by default. However this can be overridden when requiring `react-types` or on a prop-by-prop basis.\n\n```js\n// global required option\nvar types = require('react-types').Types({required: false});\n\n// prop-by-prop basis\nvar MyComponent = React.createClass({\n  propTypes: types({\n    name: String, // required\n    bio: {type: String, required: false}, // optional\n    insane: types.optional(Boolean) // optional\n  })\n});\n```\n\n### Using PropTypes inside of React Types?\n\nPropTypes has been around way longer than React Types. People have built validation on top of it and have already written their types longhand. To accommodate this situation, React Types allows PropTypes to be placed into it using `types.raw(propType)`. Examples are best:\n\n```js\nvar types = require('react-types');\n\nvar MyComponent = React.createClass({\n  propTypes: types({\n    name: types.raw(React.PropTypes.string.isRequired),\n    email: types.raw(MySuperKewlEmailValidator)\n  })\n});\n```\n\n### What else ya got? (Related projects)\n\n- [Reactbone](https://github.com/andrejewski/reactbone): React extensions for Backbone\n- [Even More Flux (EMF)](https://github.com/andrejewski/emf): Class extensions and integrations for Flux\n\n## Contributing\n\nWe can always have more tests: if you find a bug, create an issue or be **fabulous** and fix the problem and write the tests up yourself in a coherent pull request.\n\nRun tests with the `npm test` command.\n\nFollow me on [Twitter](http://chrisandrejewski.com/twitter) for updates or just for the lolz and please check out my other [repositories](https://github.com/andrejewski) if I have earned it. I thank you for reading.\n \n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fandrejewski%2Freact-types","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fandrejewski%2Freact-types","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fandrejewski%2Freact-types/lists"}