{"id":16528541,"url":"https://github.com/joshuajaco/ts-nominal","last_synced_at":"2025-10-19T00:25:21.209Z","repository":{"id":65052058,"uuid":"581347713","full_name":"joshuajaco/ts-nominal","owner":"joshuajaco","description":"Nominal typing in TypeScript","archived":false,"fork":false,"pushed_at":"2023-03-04T19:53:08.000Z","size":20,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-02-15T08:47:06.086Z","etag":null,"topics":["nominal","nominal-types","nominal-typing","typescript"],"latest_commit_sha":null,"homepage":"https://www.npmjs.com/package/ts-nominal","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/joshuajaco.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":"2022-12-22T23:44:41.000Z","updated_at":"2023-05-15T06:58:24.000Z","dependencies_parsed_at":"2022-12-25T19:32:37.340Z","dependency_job_id":null,"html_url":"https://github.com/joshuajaco/ts-nominal","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/joshuajaco%2Fts-nominal","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/joshuajaco%2Fts-nominal/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/joshuajaco%2Fts-nominal/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/joshuajaco%2Fts-nominal/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/joshuajaco","download_url":"https://codeload.github.com/joshuajaco/ts-nominal/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":241618146,"owners_count":19991805,"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":["nominal","nominal-types","nominal-typing","typescript"],"created_at":"2024-10-11T17:40:47.108Z","updated_at":"2025-10-19T00:25:16.167Z","avatar_url":"https://github.com/joshuajaco.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# ts-nominal\n\nNominal typing in TypeScript.\n\n## Installation\n\n```sh\n# npm\nnpm install ts-nominal\n\n# yarn\nyarn add ts-nominal\n\n# pnpm\npnpm install ts-nominal\n```\n\n## Usage\n\n### `Nominal\u003cT, U\u003e`\n\nCreate a nominal type from any type `T` using the unique symbol `U`.\n\n#### Example\n\n```ts\nimport type { Nominal } from \"ts-nominal\";\n\ndeclare const __FOO_STRING_ID: unique symbol;\ntype FooString = Nominal\u003cstring, typeof __FOO_STRING_ID\u003e;\n\ndeclare let foo: FooString;\ndeclare let fooLike: string;\n\n// 'FooString' can be assigned to type 'string'\nfooLike = foo;\n\n// 'string' cannot be assigned to type 'FooString'\nfoo = fooLike; // Error: Type 'string' is not assignable to type 'FooString'.\n\n// casting still works\nfoo = fooLike as FooString;\n```\n\n### `nominal\u003cT\u003e(value)`\n\nCast `value` to the nominal type `T`. Equivalent to `value as T`, but with autocompletion for `value`.  \nIt does not modify `value` in any way and has essentially no overhead on the resulting JavaScript (transpiles to `(value) =\u003e value`).\n\n#### Example\n\n```ts\nimport { type Nominal, nominal } from \"ts-nominal\";\n\ndeclare const __FOO_STRING_ID: unique symbol;\ntype FooString = Nominal\u003cstring, typeof __FOO_STRING_ID\u003e;\n\nconst foo: FooString = nominal\u003cFooString\u003e(\"foo\");\n\n// create a factory by only providing the type argument\nconst createFoo = nominal\u003cFooString\u003e;\nconst foo2 = createFoo(\"foo2\");\n\n// comparisons still function as usual\nfoo === \"foo\"; // true\nfoo === \"bar\"; // false\n```\n\n## License\n\n[MIT](https://github.com/joshuajaco/ts-nominal/blob/main/LICENSE)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjoshuajaco%2Fts-nominal","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjoshuajaco%2Fts-nominal","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjoshuajaco%2Fts-nominal/lists"}