{"id":13829019,"url":"https://github.com/gcanti/prop-types-ts","last_synced_at":"2025-08-16T09:09:30.604Z","repository":{"id":57331746,"uuid":"81745784","full_name":"gcanti/prop-types-ts","owner":"gcanti","description":"Alternative syntax for prop types providing both static and runtime type safety, powered by io-ts","archived":false,"fork":false,"pushed_at":"2020-02-05T09:37:22.000Z","size":88,"stargazers_count":171,"open_issues_count":3,"forks_count":5,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-08-13T06:30:34.752Z","etag":null,"topics":["proptype-validators","proptypes","react","typescript","validation"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/gcanti.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","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":"2017-02-12T18:06:36.000Z","updated_at":"2025-08-12T11:51:24.000Z","dependencies_parsed_at":"2022-09-05T10:11:46.106Z","dependency_job_id":null,"html_url":"https://github.com/gcanti/prop-types-ts","commit_stats":null,"previous_names":[],"tags_count":16,"template":false,"template_full_name":null,"purl":"pkg:github/gcanti/prop-types-ts","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gcanti%2Fprop-types-ts","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gcanti%2Fprop-types-ts/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gcanti%2Fprop-types-ts/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gcanti%2Fprop-types-ts/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/gcanti","download_url":"https://codeload.github.com/gcanti/prop-types-ts/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gcanti%2Fprop-types-ts/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":270254160,"owners_count":24552985,"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","status":"online","status_checked_at":"2025-08-13T02:00:09.904Z","response_time":66,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":["proptype-validators","proptypes","react","typescript","validation"],"created_at":"2024-08-04T09:03:27.620Z","updated_at":"2025-08-16T09:09:30.558Z","avatar_url":"https://github.com/gcanti.png","language":"TypeScript","funding_links":[],"categories":["TypeScript"],"sub_categories":[],"readme":"Alternative syntax for prop types powered by [io-ts](https://github.com/gcanti/io-ts)\n\n# How it works\n\nThe `@props` decorator sets `propTypes` on the target component to use a\n[custom validator function](https://facebook.github.io/react/docs/reusable-components.html#prop-validation) built around\n`io-ts` types.\n\n# Usage\n\n```ts\nimport * as React from 'react'\nimport * as t from 'io-ts'\nimport { props } from 'prop-types-ts'\n\n// define the runtime types\n\nconst AlertType = t.keyof(\n  {\n    success: true,\n    warning: true,\n    info: true\n  },\n  'AlertType'\n)\n\nconst RuntimeProps = t.interface(\n  {\n    type: AlertType\n  },\n  'Props'\n)\n\n// extract the static type\n\nexport type Props = t.TypeOf\u003ctypeof RuntimeProps\u003e\n// same as type Props = { type: 'success' | 'warning' | 'info' }\n\n@props(RuntimeProps)\nexport default class Alert extends React.Component\u003cProps, void\u003e {\n  render() {\n    return \u003cdiv\u003e{this.props.children}\u003c/div\u003e\n  }\n}\n```\n\n# Without decorators\n\n```ts\nimport { getPropTypes } from 'prop-types-ts'\n\n...\n\nexport default class Alert extends React.Component\u003cProps, void\u003e {\n  static propTypes = getPropTypes(RuntimeProps)\n  render() {\n    return \u003cdiv\u003e{this.props.children}\u003c/div\u003e\n  }\n}\n```\n\n# Errors on console\n\n```ts\n\u003cAlert type=\"foo\" /\u003e // =\u003e Invalid value \"foo\" supplied to : Props/type: AlertType\n```\n\n```ts\n\u003cAlert type=\"info\" foo=\"bar\" /\u003e // =\u003e Invalid additional prop(s): [\"foo\"]\n```\n\n# Excess Property Checks\n\nBy default `prop-types-ts` performs excess property checks. You can opt-out passing an `option` argument to `props`\n\n```ts\n@props(RuntimeProps, { strict: false })\nexport default class Alert extends React.Component\u003cProps, void\u003e {\n  ...\n}\n```\n\n# Pre-defined types\n\n`prop-types-ts` exports some useful pre-defined types:\n\n- `ReactElement`\n- `ReactChild`\n- `ReactFragment`\n- `ReactNode`\n\n# Type checking `children`\n\nUse the `children` option\n\n```ts\n@props(RuntimeProps, { children: t.string })\nexport default class Alert extends React.Component\u003cProps, void\u003e {\n  ...\n}\n\n\u003cAlert type=\"info\"\u003e{1}\u003c/Alert\u003e // =\u003e Invalid value 1 supplied to children: string\n\u003cAlert type=\"info\"\u003ehello\u003c/Alert\u003e // no errors\n```\n\nYou can use any [io-ts](https://github.com/gcanti/io-ts) type\n\n```ts\nimport { props, ReactChild } from 'prop-types-ts'\n\n@props(RuntimeProps, { children: t.tuple([t.string, ReactChild]) })\nexport default class Alert extends React.Component\u003cProps, void\u003e {\n  ...\n}\n\n\u003cAlert type=\"info\"\u003ehello\u003c/Alert\u003e // =\u003e Invalid value \"hello\" supplied to children: [string, ReactChild]\n\u003cAlert type=\"info\"\u003ehello \u003cb\u003eworld\u003c/b\u003e\u003c/Alert\u003e // no errors\n```\n\nworks for `Component`s too\n\n```ts\nimport * as t from 'io-ts'\nimport { props, ReactElement } from 'prop-types-ts'\n\nconst JSXButton = t.refinement(ReactElement, e =\u003e e.type === 'button', 'JSXButton')\n\n@props(RuntimeProps, { children: JSXButton })\nexport default class Alert extends React.Component\u003cProps, void\u003e {\n  ...\n}\n\n\u003cAlert type=\"info\"\u003ehello\u003c/Alert\u003e // =\u003e Invalid value \"hello\" supplied to children: JSXButton\n\u003cAlert type=\"info\"\u003e\u003cbutton\u003eClick me\u003c/button\u003e\u003c/Alert\u003e // no errors\n```\n\n# TypeScript compatibility\n\n| `prop-type-ts` version | required `typescript` version |\n| ---------------------- | ----------------------------- |\n| 0.7.x+                 | 3.5+                          |\n| 0.6.x+                 | 3.2+                          |\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgcanti%2Fprop-types-ts","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgcanti%2Fprop-types-ts","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgcanti%2Fprop-types-ts/lists"}