{"id":25499968,"url":"https://github.com/shoooe/derive","last_synced_at":"2025-04-10T05:52:51.474Z","repository":{"id":61606265,"uuid":"552316428","full_name":"shoooe/derive","owner":"shoooe","description":"Library to derive a TypeScript type from another.","archived":false,"fork":false,"pushed_at":"2023-07-07T14:10:30.000Z","size":7634,"stargazers_count":27,"open_issues_count":1,"forks_count":1,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-04-04T21:40:34.690Z","etag":null,"topics":["derive","graphql","types","typescript"],"latest_commit_sha":null,"homepage":"https://www.npmjs.com/package/@shoooe/derive","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/shoooe.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-10-16T10:07:49.000Z","updated_at":"2024-12-08T14:33:49.000Z","dependencies_parsed_at":"2024-06-21T15:45:09.769Z","dependency_job_id":"be032185-01c3-4295-b49d-a83e980339fc","html_url":"https://github.com/shoooe/derive","commit_stats":{"total_commits":37,"total_committers":2,"mean_commits":18.5,"dds":"0.16216216216216217","last_synced_commit":"6de679dd81b31fd97e871593f83d0518abcec9f0"},"previous_names":[],"tags_count":9,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shoooe%2Fderive","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shoooe%2Fderive/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shoooe%2Fderive/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shoooe%2Fderive/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/shoooe","download_url":"https://codeload.github.com/shoooe/derive/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248166927,"owners_count":21058480,"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":["derive","graphql","types","typescript"],"created_at":"2025-02-19T03:28:33.984Z","updated_at":"2025-04-10T05:52:51.452Z","avatar_url":"https://github.com/shoooe.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Derive\n\n[![npm version](https://badge.fury.io/js/@shoooe%2Fderive.svg)](https://badge.fury.io/js/@shoooe%2Fderive)\n\nUtility type to generate a type from another with a special care for the DX.\n\nYou can see this tool as an _hardcode_ version of `Pick`.\n\nFeatures:\n\n- 😎 Type safe\n- 🌱 Minimal \u0026 lightweight\n- ⌨️​ Autocompletion for fields\n- 💥 Automatically expands arrays and nullable/optional types\n- 👀 Preview expanded types in intellisense\n- 💫 Supports recursive \u0026 mutually recursive types\n- ❓ Optional fields support\n- 💋 Inspired by GraphQL\n\n## Installation\n\n```\nyarn add @shoooe/derive\n```\n\n## Usage\n\n### Basic usage\n\nLet's say that we have a type `User` defined as:\n\n```typescript\ntype User = {\n  bestFriend: User | undefined;\n  favoriteBook: Book | null;\n  friends: User[] | undefined;\n  id: number;\n  name: string;\n};\n\ntype Book = {\n  author: User;\n  isdn: number;\n  synopsis: string | null;\n  title: string | null | undefined;\n  subtitle?: string | null;\n};\n```\n\nWe can derive a subset of its properties via:\n\n```typescript\ntype Result = Derive\u003c\n  User,\n  {\n    id: true;\n    name: true;\n\n    // Automatically expands nullable \u0026 optional types, which means that `null`\n    // and `undefined` will be added automatically to the resulting type if\n    // they existed in the target type.\n    bestFriend: {\n      name: true;\n    };\n\n    // Automatically expands arrays as well\n    friends: {\n      name: true;\n\n      // Supports mutually recursive types\n      favoriteBook: {\n        isdn: true;\n        title: true;\n        synopsis: true;\n        author: {\n          name: true;\n        };\n      };\n    };\n  }\n\u003e;\n```\n\nWhich will result in:\n\n```typescript\ntype Result = {\n  id: number;\n  name: string;\n  bestFriend:\n    | {\n        name: string;\n      }\n    | undefined;\n  friends:\n    | {\n        name: string;\n        favoriteBook: {\n          isdn: number;\n          title: string | null | undefined;\n          synopsis: string | null;\n          author: {\n            name: string;\n          };\n        } | null;\n      }[]\n    | undefined;\n};\n```\n\n## Alternatives\n\n- [ts-essentials](https://github.com/ts-essentials/ts-essentials): comprehensive library with a different style for `DeepPick` (it doesn't do automatic expansion)\n\n## Credits\n\nSpecial thanks to:\n\n- [Perdoo](https://www.perdoo.com/) for sponsoring the initial research \u0026 implementation\n- [Szaman](https://github.com/szamanr) for the initial code review\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fshoooe%2Fderive","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fshoooe%2Fderive","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fshoooe%2Fderive/lists"}