{"id":22822596,"url":"https://github.com/manighazaee/ts-runtime-typechecker","last_synced_at":"2025-04-23T03:42:45.880Z","repository":{"id":218706707,"uuid":"723415512","full_name":"ManiGhazaee/ts-runtime-typechecker","owner":"ManiGhazaee","description":"A command line tool that generates ts/js typechecker functions from typescript types.","archived":false,"fork":false,"pushed_at":"2024-01-23T12:24:04.000Z","size":104,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-04-21T01:53:14.793Z","etag":null,"topics":["cli","command-line-tool","javascript","runtime-typechecking","rust","tools","typechecker","typescript"],"latest_commit_sha":null,"homepage":"","language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ManiGhazaee.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null}},"created_at":"2023-11-25T15:44:35.000Z","updated_at":"2024-02-03T21:12:44.000Z","dependencies_parsed_at":"2024-01-23T12:31:12.951Z","dependency_job_id":"6772fe58-974b-4d91-aad3-bb8dd85c3ef5","html_url":"https://github.com/ManiGhazaee/ts-runtime-typechecker","commit_stats":null,"previous_names":["manighazaee/ts-runtime-typechecker"],"tags_count":7,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ManiGhazaee%2Fts-runtime-typechecker","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ManiGhazaee%2Fts-runtime-typechecker/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ManiGhazaee%2Fts-runtime-typechecker/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ManiGhazaee%2Fts-runtime-typechecker/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ManiGhazaee","download_url":"https://codeload.github.com/ManiGhazaee/ts-runtime-typechecker/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250366665,"owners_count":21418767,"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":["cli","command-line-tool","javascript","runtime-typechecking","rust","tools","typechecker","typescript"],"created_at":"2024-12-12T16:12:29.640Z","updated_at":"2025-04-23T03:42:45.845Z","avatar_url":"https://github.com/ManiGhazaee.png","language":"Rust","readme":"# Typescript Runtime Typechecker\r\n\r\nA command line tool that generates TypeScript runtime typechecker functions based on interfaces in a given TypeScript file. These typechecker functions can be utilized to validate the structure and types of objects at runtime, enhancing type safety in your TypeScript projects.\r\n\r\n## Installation\r\n\r\n\u003c!-- Install the package globally with npm:\r\n\r\n```bash\r\nnpm install --global ts-runtime-typechecker \r\n``` --\u003e\r\n\r\n\u003c!-- Or --\u003e install with cargo:\r\n\r\n```bash\r\ncargo install ts-runtime-typechecker \r\n```\r\n\r\n## Usage\r\n\r\nRun the tool by providing the path to the input TypeScript file and the desired output file path:\r\n\r\n```bash\r\nts-runtime-typechecker \u003cINPUT-FILE-PATH\u003e \u003cOUTPUT-FILE-PATH\u003e\r\n```\r\n\r\n## Features\r\n\r\n### Supported\r\n\r\n- Typescript common types:\r\n  - `string` | `number` | `boolean` | `true` | `false`\r\n  - `undefined` | `null` | `unknown` | `any`\r\n  - `object` | `symbol` | `bigint`\r\n- Javascript primitives:\r\n  - string e.g. `\"str\"`\r\n  - number e.g. `12_000`\r\n- Arrays:\r\n  - `T[]`\r\n  - `Array\u003cT\u003e`\r\n- Tuples:\r\n  - `[T, U, P,...]`\r\n- Operators:\r\n  - `|`\r\n  - `\u0026`\r\n- Generics or other types:\r\n  - `Array\u003cT\u003e`\r\n  - `Function`\r\n- Interface declration merging\r\n\r\n### Not Yet Supported\r\n\r\n- Function types: e.g. `() =\u003e void`\r\n- Indexed access types: e.g. `Foo[\"bar\"]`\r\n- Conditional types: e.g. `RegExp extends Foo ? number : string`\r\n- Mapped types: e.g. `[key: string]: boolean;`\r\n- Typescript utility types: e.g. `Required\u003cT\u003e`\r\n- Some keywords: e.g. `keyof` | `typeof` | `extends` | `implements`\r\n\r\n## Example\r\n\r\nTypeScript interface `Foo` and the corresponding generated typechecker function `isFoo`.\r\n\r\n```typescript\r\n// input file:\r\ninterface Foo {\r\n    foo: string | number;\r\n    bar: \"str\" | \"\";\r\n    foobar: 0 | 100_000;\r\n    baz: number[] | null | undefined;\r\n    qux: {\r\n        faz: Array\u003cnumber\u003e;\r\n        boo: (number | \"str\")[][];\r\n        foobaz: object;\r\n        barbaz: [bigint, symbol];\r\n    };\r\n}\r\n```\r\n\r\n```typescript\r\n// output file:\r\nexport function isFoo(o: unknown): o is Foo {\r\n    return (\r\n        o != null \u0026\u0026\r\n        typeof o === \"object\" \u0026\u0026\r\n        Object.keys(o).length === 5 \u0026\u0026\r\n        \"foo\" in o \u0026\u0026\r\n        (typeof o[\"foo\"] === \"string\" || typeof o[\"foo\"] === \"number\") \u0026\u0026\r\n        \"bar\" in o \u0026\u0026\r\n        (o[\"bar\"] === \"str\" || o[\"bar\"] === \"\") \u0026\u0026\r\n        \"foobar\" in o \u0026\u0026\r\n        (o[\"foobar\"] === 0 || o[\"foobar\"] === 100000) \u0026\u0026\r\n        \"baz\" in o \u0026\u0026\r\n        ((Array.isArray(o[\"baz\"]) \u0026\u0026 typeof o[\"baz\"][\"0\"] === \"number\") ||\r\n            o[\"baz\"] === null ||\r\n            typeof o[\"baz\"] === \"undefined\") \u0026\u0026\r\n        \"qux\" in o \u0026\u0026\r\n        typeof o[\"qux\"] === \"object\" \u0026\u0026\r\n        o[\"qux\"] != null \u0026\u0026\r\n        Object.keys(o[\"qux\"]).length === 4 \u0026\u0026\r\n        \"faz\" in o[\"qux\"] \u0026\u0026\r\n        Array.isArray(o[\"qux\"][\"faz\"]) \u0026\u0026\r\n        typeof o[\"qux\"][\"faz\"][\"0\"] === \"number\" \u0026\u0026\r\n        \"boo\" in o[\"qux\"] \u0026\u0026\r\n        Array.isArray(o[\"qux\"][\"boo\"]) \u0026\u0026\r\n        (typeof o[\"qux\"][\"boo\"][\"0\"] === \"number\" ||\r\n            (Array.isArray(o[\"qux\"][\"boo\"][\"0\"]) \u0026\u0026 o[\"qux\"][\"boo\"][\"0\"][\"0\"] === \"str\")) \u0026\u0026\r\n        \"foobaz\" in o[\"qux\"] \u0026\u0026\r\n        typeof o[\"qux\"][\"foobaz\"] === \"object\" \u0026\u0026\r\n        \"barbaz\" in o[\"qux\"] \u0026\u0026\r\n        Array.isArray(o[\"qux\"][\"barbaz\"]) \u0026\u0026\r\n        o[\"qux\"][\"barbaz\"].length === 2 \u0026\u0026\r\n        typeof o[\"qux\"][\"barbaz\"][\"0\"] === \"bigint\" \u0026\u0026\r\n        typeof o[\"qux\"][\"barbaz\"][\"1\"] === \"symbol\"\r\n    );\r\n}\r\n```\r\n\r\n___\r\n\r\nTypeScript interfaces `Bar`, `Baz` and the corresponding generated typechecker functions `isBar`, `isBaz`.\r\n\r\n```typescript\r\n// input file:\r\ninterface Bar {\r\n    foo: number | Baz;\r\n}\r\n\r\ninterface Baz {\r\n    foo: string;\r\n}\r\n\r\ninterface Bar {\r\n    bar: [Baz]\r\n}\r\n```\r\n\r\n```typescript\r\n// output file:\r\nexport function isBar(o: unknown): o is Bar {\r\n    return (\r\n        o != null \u0026\u0026\r\n        typeof o === \"object\" \u0026\u0026\r\n        Object.keys(o).length === 2 \u0026\u0026\r\n        \"foo\" in o \u0026\u0026\r\n        (typeof o[\"foo\"] === \"number\" ||\r\n            (typeof o[\"foo\"] === \"object\" \u0026\u0026\r\n                o[\"foo\"] != null \u0026\u0026\r\n                Object.keys(o[\"foo\"]).length === 1 \u0026\u0026\r\n                \"foo\" in o[\"foo\"] \u0026\u0026\r\n                typeof o[\"foo\"][\"foo\"] === \"string\")) \u0026\u0026\r\n        \"bar\" in o \u0026\u0026\r\n        Array.isArray(o[\"bar\"]) \u0026\u0026\r\n        o[\"bar\"].length === 1 \u0026\u0026\r\n        typeof o[\"bar\"][\"0\"] === \"object\" \u0026\u0026\r\n        o[\"bar\"][\"0\"] != null \u0026\u0026\r\n        Object.keys(o[\"bar\"][\"0\"]).length === 1 \u0026\u0026\r\n        \"foo\" in o[\"bar\"][\"0\"] \u0026\u0026\r\n        typeof o[\"bar\"][\"0\"][\"foo\"] === \"string\"\r\n    );\r\n}\r\n\r\nexport function isBaz(o: unknown): o is Baz {\r\n    return (\r\n        o != null \u0026\u0026 typeof o === \"object\" \u0026\u0026 Object.keys(o).length === 1 \u0026\u0026 \"foo\" in o \u0026\u0026 typeof o[\"foo\"] === \"string\"\r\n    );\r\n}\r\n```\r\n\r\n## License\r\n\r\nThis project is licensed under the GNU General Public License v3.0 - see the [LICENSE](./LICENSE.md) file for details.\r\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmanighazaee%2Fts-runtime-typechecker","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmanighazaee%2Fts-runtime-typechecker","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmanighazaee%2Fts-runtime-typechecker/lists"}