{"id":15365940,"url":"https://github.com/andywer/type-reflect","last_synced_at":"2025-04-15T10:51:32.179Z","repository":{"id":57383238,"uuid":"152991504","full_name":"andywer/type-reflect","owner":"andywer","description":"☝️ TypeScript plugin providing access to type information at runtime","archived":false,"fork":false,"pushed_at":"2018-10-15T20:00:38.000Z","size":44,"stargazers_count":11,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-28T19:13:12.626Z","etag":null,"topics":["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/andywer.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":"2018-10-14T15:54:33.000Z","updated_at":"2022-08-11T14:43:06.000Z","dependencies_parsed_at":"2022-09-26T19:52:32.414Z","dependency_job_id":null,"html_url":"https://github.com/andywer/type-reflect","commit_stats":null,"previous_names":["andywer/ts-reflect"],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/andywer%2Ftype-reflect","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/andywer%2Ftype-reflect/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/andywer%2Ftype-reflect/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/andywer%2Ftype-reflect/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/andywer","download_url":"https://codeload.github.com/andywer/type-reflect/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":249057628,"owners_count":21205905,"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":["typescript"],"created_at":"2024-10-01T13:16:45.380Z","updated_at":"2025-04-15T10:51:32.143Z","avatar_url":"https://github.com/andywer.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# type-reflect\n\nTypeScript transformation plugin that provides access to TypeScript type information at runtime. Comes with a validation function and a type-checking `JSON.parse()`.\n\nUse with TypeScript 3.\n\n⚠️ Status: Experimental\n\n\n## Installation\n\n```sh\n$ npm install type-reflect\n```\n\n\n## Usage\n\nAccessing type information in your code is easy:\n\n```ts\nimport Reflect from \"type-reflect\"\n\ninterface User {\n  name: string,\n  role: \"admin\" | \"read-write\" | \"read-only\"\n}\n\nexport const schema = Reflect\u003cUser\u003e()\n```\n\nThe `Reflect\u003c\u003e()` call above will be transpiled to:\n\n```ts\nexport const schema = {\n  type: \"object\",\n  title: \"User\",\n  properties: {\n    name: {\n      type: \"string\"\n    },\n    role: {\n      type: \"string\",\n      enum: [\"admin\", \"read-write\", \"read-only\"]\n    }\n  },\n  required: [\"id\", \"name\", \"role\"]\n}\n```\n\nIt works with all kinds of types, like strings, `any`, objects, arrays and much more:\n\n```ts\nconst ageSchema = Reflect\u003c\"new\" | \"old\"\u003e()\n```\n\n### Validating data\n\n```ts\nimport { validate } from \"type-reflect/validate\"\nimport { getUser } from \"./user\"\nimport { schema } from \"./user-schema\"\n\nconst user = validate(getUser(), schema)\n\n// Throws if the return value of `getUser()` does not match the schema\n// TypeScript can automatically infer that `user` is of type `User`\n```\n\n### Validated JSON parsing\n\n```ts\nimport { parseJSON } from \"type-reflect/validate\"\nimport { schema } from \"./user-schema\"\n\nconst json = `{\n  \"name\": \"Me\",\n  \"role\": \"read-write\"\n}`\n\nconst user = parseJSON(json, schema)\n\n// Throws if the JSON data does not match the schema\n// TypeScript can automatically infer that `user` is of type `User`\n```\n\n\n## Compilation\n\nTo transpile the TypeScript code using the `type-reflect` transformation, use the [`ts` compiler](https://github.com/andywer/ts):\n\n```sh\n$ ts --transform type-reflect/transform ./source.ts\n```\n\nTo permanently use the transformation in your project, add this configuration to your `package.json`:\n\n```js\n{\n  // ...\n  \"ts\": {\n    \"transforms\": [\n      \"type-reflect\"\n    ]\n  }\n}\n```\n\nNote that you cannot use the standard `tsc`, since it does not expose the transformation API.\n\n\n## Known Limitations\n\n- Generic types / interfaces do not work correctly yet (generic type arguments don't work)\n- Tuples are casted to `any[]` right now\n\n\n## License\n\nMIT\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fandywer%2Ftype-reflect","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fandywer%2Ftype-reflect","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fandywer%2Ftype-reflect/lists"}