{"id":21041939,"url":"https://github.com/supernavix/ts-transform-nameof","last_synced_at":"2026-05-12T16:08:43.756Z","repository":{"id":57381241,"uuid":"122432346","full_name":"SupernaviX/ts-transform-nameof","owner":"SupernaviX","description":"A custom TypeScript transformer that exposes the name of a type at runtime. It can also transform function calls to pass those names in automatically.","archived":false,"fork":false,"pushed_at":"2018-03-05T03:02:45.000Z","size":14,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-02-20T22:35:31.710Z","etag":null,"topics":["typescript","typescript-compiler"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/SupernaviX.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-02-22T04:53:06.000Z","updated_at":"2018-02-26T16:15:48.000Z","dependencies_parsed_at":"2022-09-05T13:40:42.869Z","dependency_job_id":null,"html_url":"https://github.com/SupernaviX/ts-transform-nameof","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SupernaviX%2Fts-transform-nameof","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SupernaviX%2Fts-transform-nameof/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SupernaviX%2Fts-transform-nameof/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SupernaviX%2Fts-transform-nameof/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/SupernaviX","download_url":"https://codeload.github.com/SupernaviX/ts-transform-nameof/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243489336,"owners_count":20298990,"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","typescript-compiler"],"created_at":"2024-11-19T13:56:55.845Z","updated_at":"2025-12-29T17:02:07.406Z","avatar_url":"https://github.com/SupernaviX.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# ts-transform-nameof\n\nA custom TypeScript transformer that exposes the name of a type at runtime. It can also transform function calls to pass those names in automatically.\n\n## Setup\n- Install [ttypescript](https://github.com/cevek/ttypescript)\n- Add this to `tsconfig.json`:\n```json\n{\n  \"compilerOptions\": {\n    \"plugins\": [\n      {\n        \"customTransformers\": {\n          \"before\": [\n            \"ts-transform-nameof/transformer\"\n          ]\n        }\n      }\n    ]\n  }\n}\n```\n\n## How to use it\n```typescript\nimport { nameof } from 'ts-transform-nameof';\n\nclass Repository\u003cT\u003e {\n  public constructor(private typeName: string = nameof\u003cT\u003e()) {\n    console.log(`Creating new repo for ${typeName}`);\n  }\n}\n\n// In some other file...\nconst repo = new Repository\u003cSomeInterface\u003e();\n// At runtime, this will be passed the string \"SomeInterface\"\n```\n\n## How does it work\n```typescript\n// At compile time, this typescript...\nfunction getType\u003cT\u003e(param: T, type = nameof\u003cT\u003e()) {\n  console.log(`param is a ${type}`);\n}\ngetType(true);\n\n// gets transpiled to this...\nfunction getType(param, type) {\n  if (type === void 0) { type = nameof(\"T\"); }\n  console.log(`param is a ${type}`);\n}\ngetType(true, \"boolean\");\n```\nThis custom transformer uses the TypeChecker API to find the name of `nameof`'s generic argument.\n\n## Limitations\nTo transform a function call, the type checker needs to know about the function's body. This means that function calls won't be transpiled when:\n- The function is being called through an interface\n- The function was exported by another npm package\n\nIf a function call doesn't get transformed, `nameof\u003cT\u003e()` will actually get called, and return `\"T\"` (or whatever its parameter was named).","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsupernavix%2Fts-transform-nameof","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsupernavix%2Fts-transform-nameof","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsupernavix%2Fts-transform-nameof/lists"}