{"id":15645206,"url":"https://github.com/cryrivers/magic-type","last_synced_at":"2025-10-04T15:43:37.482Z","repository":{"id":151792584,"uuid":"167170499","full_name":"Cryrivers/magic-type","owner":"Cryrivers","description":"🎩 Use Your TypeScript definitions at runtime. Powered by Manta Style.","archived":false,"fork":false,"pushed_at":"2019-02-15T07:46:29.000Z","size":602,"stargazers_count":54,"open_issues_count":1,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-30T10:33:14.481Z","etag":null,"topics":["type-safety","typescript"],"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/Cryrivers.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":"2019-01-23T11:18:25.000Z","updated_at":"2024-10-25T15:39:06.000Z","dependencies_parsed_at":null,"dependency_job_id":"c6ba516a-17c8-467d-8c28-0044af9baeca","html_url":"https://github.com/Cryrivers/magic-type","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/Cryrivers/magic-type","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Cryrivers%2Fmagic-type","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Cryrivers%2Fmagic-type/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Cryrivers%2Fmagic-type/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Cryrivers%2Fmagic-type/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Cryrivers","download_url":"https://codeload.github.com/Cryrivers/magic-type/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Cryrivers%2Fmagic-type/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":278335449,"owners_count":25970078,"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-10-04T02:00:05.491Z","response_time":63,"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":["type-safety","typescript"],"created_at":"2024-10-03T12:05:07.674Z","updated_at":"2025-10-04T15:43:37.465Z","avatar_url":"https://github.com/Cryrivers.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003ch1 align=\"center\"\u003e\n  Magic Type\n\u003c/h1\u003e\n\u003cp align=\"center\"\u003e🎩 Use Your TypeScript definitions at runtime. Powered by \u003ca href=\"https://github.com/Cryrivers/manta-style\" target=\"_blank\"\u003eManta Style\u003c/a\u003e.\u003c/p\u003e\n\u003cp align=\"center\"\u003e\n\u003cimg src=\"https://img.shields.io/npm/v/magic-type.svg?style=flat-square\" alt=\"version\"\u003e\n\u003ca href=\"https://github.com/Cryrivers/magic-type/blob/master/LICENSE\"\u003e\u003cimg src=\"https://img.shields.io/github/license/Cryrivers/magic-type.svg?style=flat-square\" alt=\"GitHub\" /\u003e\u003c/a\u003e\n\u003c/p\u003e\n\n---\n\n# Installation\n\n- With Yarn\n\n```sh\nyarn global add magic-type\n```\n\n- With NPM\n\n```sh\nnpm install -g magic-type\n```\n\nYou could also use Magic Type locally as well.\n\n# Usage\n\nLet's take the following code as an example.\n\n```typescript\n// typings/api.ts\nexport type MyAPIRequest = {\n  time: number;\n  input: string;\n};\n```\n\n## Compile TypeScript definitions\n\n[![asciicast](https://asciinema.org/a/VAwlNHFdww9mqracrAJJDWTlf.png)](https://asciinema.org/a/VAwlNHFdww9mqracrAJJDWTlf?speed=0.85)\n\n```\nUsage: magictype [options]\n\nOptions:\n  -V, --version          output the version number\n  -i --inputFile \u003cfile\u003e  The entrypoint of files to be compiled\n  -o --outputDir \u003cdir\u003e   The output directory of compiled files\n  -c --cjs               Transpile modules to CommonJS (Otherwise it will output ES modules)\n  -h, --help             output usage information\n```\n\n## Use magic types at runtime\n\n```typescript\nimport { MyAPIRequest } from \"./api\";\n\n// Use Magic Types as normal TypeScript types\ntype MyType = {\n  key: MyAPIRequest;\n};\n\n// Use Magic Type at Runtime\n\n// Check if user input matches MyAPIRequest\nfunction checkMyInput(input: any) {\n  return MyAPIRequest.validate(input);\n}\n\n// Format user input to match MyAPIRequest\nfunction formatMyInput(input: any) {\n  return MyAPIRequest.format(input);\n}\n\n// Generate a mock MyAPIRequest data\nfunction getMockData() {\n  return MyAPIRequest.deriveLiteral([]).mock();\n}\n```\n\n- Developer Experience with TypeScript's [type guard](https://basarat.gitbooks.io/typescript/docs/types/typeGuard.html#user-defined-type-guards)\n  ![Developer Experience](https://raw.githubusercontent.com/Cryrivers/magic-type/master/media/dev-experience.png)\n\n- Runtime Screenshot:\n  ![Runtime Screenshot](https://raw.githubusercontent.com/Cryrivers/magic-type/master/media/magic-type-runtime-example.png)\n\n# Unsupported Syntax\n\nPlease be noted there's no warnings against unsupported syntax yet (And Magic Type may crash as well).\nPlease kindly check by yourself.\n\n- `extends` keyword in `interface` declaration will be ignored.\n- Union (`A | B`) and intersection(`A \u0026 B`) on index signatures are not supported.\n- Functions\n- `infer` keyword\n- `ReturnType\u003cT\u003e` and `InstanceType\u003cT\u003e` are not supported due to unsupported `infer` keyword and functions.\n\n# License\n\nMagic Type is [MIT licensed](https://github.com/Cryrivers/magic-type/blob/master/LICENSE)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcryrivers%2Fmagic-type","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcryrivers%2Fmagic-type","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcryrivers%2Fmagic-type/lists"}