{"id":34647216,"url":"https://github.com/ascandone/ts-decode","last_synced_at":"2026-04-17T19:02:51.657Z","repository":{"id":45414339,"uuid":"434166633","full_name":"ascandone/ts-decode","owner":"ascandone","description":"Straightforward, type-safe `unknown =\u003e T` decoding combinators","archived":false,"fork":false,"pushed_at":"2024-02-08T21:38:16.000Z","size":418,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-10-06T14:54:49.399Z","etag":null,"topics":["decoding","json","typesafe","typescript","validation"],"latest_commit_sha":null,"homepage":"https://ts-decode.netlify.app/modules","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ascandone.png","metadata":{"files":{"readme":"readme.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2021-12-02T09:57:34.000Z","updated_at":"2021-12-14T22:52:17.000Z","dependencies_parsed_at":"2024-11-06T21:50:27.875Z","dependency_job_id":null,"html_url":"https://github.com/ascandone/ts-decode","commit_stats":{"total_commits":141,"total_committers":1,"mean_commits":141.0,"dds":0.0,"last_synced_commit":"f8db8a5a3a82f4c8ed49bf13e41f24231078bc0f"},"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"purl":"pkg:github/ascandone/ts-decode","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ascandone%2Fts-decode","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ascandone%2Fts-decode/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ascandone%2Fts-decode/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ascandone%2Fts-decode/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ascandone","download_url":"https://codeload.github.com/ascandone/ts-decode/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ascandone%2Fts-decode/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":31941845,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-17T17:29:20.459Z","status":"ssl_error","status_checked_at":"2026-04-17T17:28:47.801Z","response_time":62,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"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":["decoding","json","typesafe","typescript","validation"],"created_at":"2025-12-24T17:48:22.462Z","updated_at":"2026-04-17T19:02:51.645Z","avatar_url":"https://github.com/ascandone.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![npm version](https://badgen.net/npm/v/ts-decode)](https://www.npmjs.com/package/ts-decode) ![build status](https://badgen.net/github/checks/styfle/packagephobia/main) ![codecov](https://badgen.net/codecov/c/github/ascandone/ts-decode/master)\n\n![minzipped size](https://badgen.net/bundlephobia/minzip/ts-decode@latest) ![Dependency count](https://badgen.net/bundlephobia/dependency-count/ts-decode) ![tree shaking](https://badgen.net/bundlephobia/tree-shaking/ts-decode@latest)\n\n## `ts-decode`\n\n\u003e Straightforward, type-safe `unknown =\u003e T` decoding combinators\n\n### Install\n\n```bash\n# using npm\nnpm i ts-decode\n\n# using yarn\nyarn add ts-decode\n```\n\n### Usage\n\n```ts\n// We can compose the decoders to create new decoders\n\nconst personTypeDecoder = oneOf(\n  hardcoded(\"developer\"),\n  hardcoded(\"project manager\"),\n  hardcoded(\"designer\"),\n);\n\nconst personDecoder = object({\n  name: string.required,\n  id: number.required,\n  kind: personTypeDecoder.required,\n  phoneNumbers: array(string).optional,\n});\n\n/*\nAutomagically inferred as:\n\ntype Person = {\n    name: string;\n    id: number;\n    kind: \"developer\" | \"project manager\" | \"designer\";\n    phoneNumbers?: string[] | undefined;\n}\n*/\ntype Person = Infer\u003ctypeof personDecoder\u003e;\n\n// The decoder can now validate a value of unknown type\nconst json = JSON.parse(`\n  { \"name\": \"John Doe\",\n    \"id\": 1234,\n    \"kind\": \"project-manager\",\n    \"phoneNumbers\": [\"123123123\"]\n  }\n`);\n\nconst result = personDecoder.decode(json);\n\nif (result.error === false) {\n  // now we have the compile-time guarantee that this\n  const person = result.value;\n  // has type `Person` without manual casting\n} else {\n  // Or if it failed we can log the error description\n  const reason = result.reason;\n  console.error(reasonToXmlString(reason));\n}\n```\n\nBy the way, did you notice the bug?\nGood thing we printed it out\n\n```xml\n\u003cfield-type name=\"kind\"\u003e\n  \u003cone-of\u003e\n    \u003cfail\u003e Expected \"developer\", got \"project-manager\" instead  \u003c/fail\u003e\n    \u003cfail\u003e Expected \"project manager\", got \"project-manager\" instead  \u003c/fail\u003e\n    \u003cfail\u003e Expected \"designer\", got \"project-manager\" instead  \u003c/fail\u003e\n  \u003c/one-of\u003e\n\u003c/field-type\u003e\n```\n\nYou can find the complete typedocs-generated API [here](https://ts-decode.netlify.app/modules.html) or you can try it in a [codesanbox](https://codesandbox.io/s/ts-decode-playground-xw3yb?file=/src/index.ts)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fascandone%2Fts-decode","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fascandone%2Fts-decode","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fascandone%2Fts-decode/lists"}