{"id":13727055,"url":"https://github.com/ENvironmentSet/ts-transfromer-typerep","last_synced_at":"2025-05-07T22:30:48.950Z","repository":{"id":57381287,"uuid":"329863143","full_name":"ENvironmentSet/ts-transfromer-typerep","owner":"ENvironmentSet","description":"Bring type level information to value level.","archived":false,"fork":false,"pushed_at":"2024-08-07T07:52:31.000Z","size":51,"stargazers_count":19,"open_issues_count":0,"forks_count":1,"subscribers_count":3,"default_branch":"main","last_synced_at":"2025-04-02T15:47:50.393Z","etag":null,"topics":["type-level-programming","typescript","typescript-transformer"],"latest_commit_sha":null,"homepage":"https://stackblitz.com/edit/webpack-webpack-js-org-7mxehx?file=src%2Fmain.ts","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/ENvironmentSet.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-01-15T09:13:51.000Z","updated_at":"2024-08-07T07:56:43.000Z","dependencies_parsed_at":"2024-11-14T17:43:13.318Z","dependency_job_id":null,"html_url":"https://github.com/ENvironmentSet/ts-transfromer-typerep","commit_stats":null,"previous_names":["environmentset/ts-typerep"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ENvironmentSet%2Fts-transfromer-typerep","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ENvironmentSet%2Fts-transfromer-typerep/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ENvironmentSet%2Fts-transfromer-typerep/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ENvironmentSet%2Fts-transfromer-typerep/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ENvironmentSet","download_url":"https://codeload.github.com/ENvironmentSet/ts-transfromer-typerep/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252330428,"owners_count":21730683,"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":["type-level-programming","typescript","typescript-transformer"],"created_at":"2024-08-03T01:03:37.701Z","updated_at":"2025-05-07T22:30:48.938Z","avatar_url":"https://github.com/ENvironmentSet.png","language":"TypeScript","funding_links":[],"categories":["TypeScript"],"sub_categories":[],"readme":"# ts-transformer-typerep\n\nA typescript custom transformer which enables a programmer to pull down type-level(compile time) information into value level(runtime).\n\n```typescript\nimport { typeRep, TypeKind } from 'ts-transformer-typerep';\n\nfunction keys\u003cT\u003e(): string[] {\n  const type = typeRep\u003cT\u003e();\n\n  if (type.kind === TypeKind.Object) return type.properties.map(([key]) =\u003e key);\n  else return [];\n}\n\nkeys\u003c{ x: 1, y: 2, z: 3 }\u003e(); // ['x', 'y', 'z']\n```\n\n\u003e **WARNING⚠️**: This transformer is on experiment. It's not recommended to use this in product.\n\n## Installation\n\n```shell script\nnpm i -D ts-transformer-typerep\n```\n\n[Check here](https://github.com/madou/typescript-transformer-handbook#consuming-transformers) and [here](https://github.com/nonara/ts-patch?tab=readme-ov-file#configuration) to learn how to apply custom transformers.\n\n## Reference\n\n### Type `TypeRep`\n\nType representations are values that represent types. `TypeRep` is type of all type representation.\nSince typescript types can be classified in several groups, type representations are classified in groups, too.\n\n| Type | Type Representation                                                                      |\n|------|------------------------------------------------------------------------------------------|\n| `any` | `AnyRep`(`{ kind: TypeKind.Any }`)                                                       |\n| `number` and its subtypes | `NumberRep`(`{ kind: TypeKind.Number, literal: number }`)                                |\n| `boolean` and its subtypes | `BooleanRep`(`{ kind: TypeKind.Boolean, literal: boolean }`)                             |\n| `string` and its subtypes | `StringRep`(`{ kind: TypeKind.String, literal: string }`)                                |\n| `symbol` | `SymbolRep`(`{ kind: TypeKind.Symbol }`)                                                 |\n| `bigint` and its subtypes | `BigIntRep`(`{ kind: TypeKind.BigInt, literal: bigint }`)                                |\n| `null` | `NullRep`(`{ kind: TypeKind.null }`)                                                     |\n| `undefined` | `UndefinedRep`(`{ kind: TypeKind.Undefined }`)                                           |\n| `object` | `NonPrimitiveRep`((`{ kind: TypeKind.NonPrimitive }`)                                    |\n| `unknown` | `UnknownRep`(`{ kind: TypeKind.Unknown }`)                                               |\n| `never` | `NeverRep`(`{ kind: TypeKind.Never }`)                                                   |\n| `void` | `VoidRep`(`{ kind: TypeKind.Void }`)                                                     |\n| Any type constructed with Union operator but not `never` | `UnionRep`(`{ kind: TypeKind.Union, parts: TypeRep[] }`)                                 |\n| Any type constructed with Intersection operator | `IntersectionRep`(`{ kind: TypeKind.Intersection, parts: TypeRep[] }`)                   |\n| Any object type with call signautre | `FunctionRep`(`{ kind: TypeKind.Function, parameters: TypeRep[], returnType: TypeRep }`) |\n\n### Type `TypeKind`\n\n`TypeKind` is type of values for discriminating different type representations.\nDifferent type representations are distinguished by its `kind` field, whose value is value of `TypeKind`.\n\n```typescript\nconst type = typeRep\u003cnumber\u003e();\n\nif (type.kind === TypeKind.Number) console.log('It\\'s a number type!');\nelse console.log('It\\'s not a number type :(');\n```\n\n| Type | TypeKind |\n|------|----------|\n| `any` | `Any` |\n| `number` and its subtypes | `Number` |\n| `boolean` and its subtypes | `Boolean` |\n| `string` and its subtypes | `String` |\n| `symbol` | `Symbol` |\n| `bigint` and its subtypes | `BigInt` |\n| `null` | `Null` |\n| `undefined` | `Undefined` |\n| Any object type excluding subtypes of `Object` | `NonPrimitive` |\n| `unknown` | `Unknown` |\n| `never` | `Never` |\n| `void` | `Void` |\n| Any type constructed with Union operator but not `never` | `Union` |\n| Any type constructed with Intersection operator | `Intersection` |\n| `Object` | `Object` |\n| Any object type with call signature | `Function` |\n\n### Function `typeRep\u003ctypeToPullDown\u003e(): TypeRep`\n\n`typeRep` is a function to pull type level information into value level. It returns a type representation of given type.\n\n```typescript\ntypeRep\u003c10\u003e();\n/**\n{\n  kind: TypeKind.Number,\n  literal: 10\n}\n**/\n```\n\n\u003e **WARNING⚠️**: This function is not fully implemented yet, please refer to following 'Type Support Table' to check which types it supports.\n\n#### Type Support Table\n\n- Available(✅): A type is fully supported\n- WIP(🚧): A type is partially supported\n- Todo(📝): A type is planned to be supported\n\n| Types | Current State |\n|---------|---------------|\n| Primitive types | ✅ |\n| Literal types | ✅ |\n| `never`/`unknown`/`any`/`void` | ✅ |\n| Polymorphic types | 🚧(Single type variable such as `T`, `A` only) |\n| Enums | 📝 |\n| Function types | ✅ |\n| Union types | ✅ |\n| Intersection types | ✅ |\n| Template literal types | 📝 |\n| Object types | ✅ |","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FENvironmentSet%2Fts-transfromer-typerep","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FENvironmentSet%2Fts-transfromer-typerep","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FENvironmentSet%2Fts-transfromer-typerep/lists"}