{"id":43755720,"url":"https://github.com/ahrjarrett/any-ts","last_synced_at":"2026-02-05T14:23:37.234Z","repository":{"id":217033213,"uuid":"741507069","full_name":"ahrjarrett/any-ts","owner":"ahrjarrett","description":"Sensible, performant primitives for writing semantic TypeScript code","archived":false,"fork":false,"pushed_at":"2024-11-16T03:03:50.000Z","size":746,"stargazers_count":14,"open_issues_count":4,"forks_count":1,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-10-13T09:55:09.999Z","etag":null,"topics":["any-type","namespace","newtype","typelevel","typelevel-programming","typescript","typescript-namespaces"],"latest_commit_sha":null,"homepage":"https://npmjs.com/package/any-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/ahrjarrett.png","metadata":{"files":{"readme":"readme.md","changelog":"CHANGELOG.md","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":"2024-01-10T14:39:17.000Z","updated_at":"2025-08-05T13:55:13.000Z","dependencies_parsed_at":"2024-01-14T07:20:46.487Z","dependency_job_id":"1ed3c85a-cfea-4026-9d74-ad494eecf39b","html_url":"https://github.com/ahrjarrett/any-ts","commit_stats":null,"previous_names":["ahrjarrett/any"],"tags_count":34,"template":false,"template_full_name":null,"purl":"pkg:github/ahrjarrett/any-ts","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ahrjarrett%2Fany-ts","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ahrjarrett%2Fany-ts/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ahrjarrett%2Fany-ts/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ahrjarrett%2Fany-ts/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ahrjarrett","download_url":"https://codeload.github.com/ahrjarrett/any-ts/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ahrjarrett%2Fany-ts/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29123675,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-05T14:05:12.718Z","status":"ssl_error","status_checked_at":"2026-02-05T14:03:53.078Z","response_time":65,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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":["any-type","namespace","newtype","typelevel","typelevel-programming","typescript","typescript-namespaces"],"created_at":"2026-02-05T14:23:36.004Z","updated_at":"2026-02-05T14:23:37.227Z","avatar_url":"https://github.com/ahrjarrett.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"\n\u003cbr\u003e\n\u003ch2 align=\"center\"\u003e𝗮𝗻𝘆-𝘁𝘀\u003c/h2\u003e\n\u003cbr\u003e\n\n[![NPM Package][]](https://npmjs.org/package/any-ts)\n\n[npm package]: https://img.shields.io/npm/v/any-ts.svg?color=44bb17\n\n[any-ts](https://github.com/ahrjarrett/any-ts) is a small set of TypeScript namespaces that overload built-in names (like [`any`](https://www.typescriptlang.org/docs/handbook/2/everyday-types.html#any)) to make them extensible.\n\n\u003e [!NOTE]\n\u003e Currently, `any-ts` is **BYOI**: \"bring your own implementation\". With the exception of the [`ANY_TS_VERSION`](https://github.com/ahrjarrett/any-ts/blob/main/src/version.ts#L1-L2) constant, `any-ts` only ships _type declarations_.\n\n## Requirements\n- [TypeScript v5.0](https://devblogs.microsoft.com/typescript/announcing-typescript-5-0/) or greater\n- The [`strict`](https://www.typescriptlang.org/tsconfig/#strict) compiler option enabled in your `tsconfig.json`:\n\n## What problem does `any-ts` solve?\n\nThe reason `any-ts` exists is because TypeScript types are hard to get right.\n\nThe TypeScript team has invested a lot of time into making their syntax beginner friendly, and easy to use.\n\nThe problem, as anyone who's used TypeScript for some time knows, is that while the type system is incredibly powerful, it's also incredibly 🦄 _magical_ 🌈.\n\nI think most TS users would agree:\n\n\u003e **While TypeScript is, in some ways, \"easy\" to use, it's not simple.** \n\nSome of this complexity, we feel, is avoidable. Let's look at an example.\n\nLet's say you're writing a small library of helper functions:\n\n```typescript\n/**\n * `identity` is a function that takes any arbitrary input, captures as much type\n * information as possible, and returns it to you:\n */\nconst identity = \u003cconst type\u003e(term: type): type =\u003e term\n\n/** `flatten` is a variadic function that takes a list of arrays and... well, flattens them. */\nconst flatten = \u003cconst T extends Array\u003cArray\u003cany\u003e\u003e\u003e(...arrays: T) =\u003e arrays.flat()\n```\n\nYou write some tests, everything works as expected, so you ship it. Nice work!\n\nBut before long, someone creates an issue. Here's what they tried to do:\n\n```typescript\nimport { identity, flatten } from \"helpful-helpers\"\n\nconst arr1 = identity([0, 1, 2, 3])\nconst arr2 = identity([4, 5, 6, 7])\n\nconst arr3 = flatten(arr1, arr2)\n//                   ^^^^ 🚫 TypeError\n```\n\n\u003e Can you spot the problem?\n\n\nThe problem here is that `arr1` has the type `readonly [1, 2, 3]`, and `flatten` only accepts mutable arrays.\n\nYou do some research and find it that every `ReadonlyArray`, despite having the longer, more \"qualified\" name, does not extend `Array`.\n\nIn fact, it's actually the other way around: **every `Array` is a structural subtype of `ReadonlyArray`**.\n\nHere's how `any-ts` solves this problem:\n\n```typescript\nimport type { any } from \"any-ts\"\n\nconst identity = \u003cconst type\u003e(term: type): type =\u003e term\n\nconst flatten = \u003cconst T extends any.array\u003cany.array\u003e\u003e(...arrays: T) =\u003e arrays.flat()\n\nconst arr1 = identity([0, 1, 2, 3])\nconst arr2 = identity([4, 5, 6, 7])\n\nflatten(arr1, arr2)\n// no type error\n```\n\n### What's happening?\n\nIf you're troubled by the `any.array\u003cany.array\u003e` syntax, don't worry: it's not as cursed as it might sound.\n\n#### But how are you adding properties to `any`, as if it were an object?\n\nThe short answer is that types and namespaces can share identifiers. This has been the case for years. And unlike objects, namespace can export types.\n\nAll we've done is overload `any`, which allows us to piggyback on its semantics. `any` is still `any`, and `any.array` is a type that absorbs the complexity (and verbosity) of `readonly unknown[]`.\n\n#### But what if I want an array of strings?\n\n```typescript\nimport type { any } from \"any-ts\"\n\ntype myStringArray = any.array\u003cstring\u003e\n//   readonly string[]\n```\n\n#### But what if I want a mutable array?\n\nWith `any-ts`, your intent is explicit:\n\n```typescript\nimport type { any, mut } from \"any-ts\"\n\ntype myMutableArray = mut.array\n//   ^? type myMutableArray = unknown[]\ntype myMutableStringArray = mut.array\u003cstring\u003e\n//   ^? type myMutableStringArray = string[]\n\n// or, if you prefer not importing both:\ntype myOtherArray = any.mut.array\n//   ^? type myOtherArray = unknown[]\n\ntype myOtherStringArray = any.mut.array\u003cstring\u003e\n//   ^? type myOtherStringArray = string[]\n```\n\n#### But what if I want to express more advanced types?\n\nIn our opinion, this is where `any-ts` really shines.\n\nIf you're a power user, you can do some pretty cool things with `any-ts`. Let's continue using `any.array`, even though it's one of the simplest types the library implements.\n\nWhat if you wanted to _extract_ (or pattern-match) the type that an array holds?\n\n```typescript\ndeclare namespace Dictionary {\n  type fromArray\u003cxs extends any.array\u003e \n    = xs extends any.array\u003cinfer x\u003e ? Record\u003cstring, x\u003e : never;\n}\n\ntype featureFlags = Dictionary.fromArray\u003cboolean[]\u003e\n//   ^? type featureFlags = Record\u003cstring, boolean\u003e\n```\n\nOf the hundreds of types that `any-ts` ships, almost all of them can be used in _matching position_, like above.\n\nIf you're looking for more examples, you can find more in the [examples](https://github.com/ahrjarrett/any-ts/tree/main/src/examples) directory (WIP).\n\nLooking for something that we don't ship yet? [Raise an issue](https://github.com/ahrjarrett/any-ts/issues/new) -- we'd love to try to help!\n\n### Namespaces\n\n- [`any`](https://github.com/ahrjarrett/any-ts/blob/main/src/any.ts)\n- [`array`](https://github.com/ahrjarrett/any-ts/blob/main/src/array/array.ts)\n- [`boolean`](https://github.com/ahrjarrett/any-ts/blob/main/src/boolean/boolean.ts)\n- [`char`](https://github.com/ahrjarrett/any-ts/blob/main/src/string/char.ts)\n- [`empty`](https://github.com/ahrjarrett/any-ts/blob/main/src/empty.ts)\n- [`Kind`](https://github.com/ahrjarrett/any-ts/blob/main/src/kind/kind.ts), a simple but powerful [HKT](https://en.wikipedia.org/wiki/Kind_(type_theory)) encoding that supports partial application \u0026 re-binding\n- [`Identity`](https://github.com/ahrjarrett/any-ts/blob/main/src/identity.ts)\n- [`integer`](https://github.com/ahrjarrett/any-ts/blob/main/src/number/integer.ts)\n- [`mut`](https://github.com/ahrjarrett/any-ts/blob/main/src/mutable/mutable.ts)\n- [`never`](https://github.com/ahrjarrett/any-ts/blob/main/src/never/never.ts), a.k.a. \"semantic never\"\n- [`nonempty`](https://github.com/ahrjarrett/any-ts/blob/main/src/empty.ts)\n- [`number`](https://github.com/ahrjarrett/any-ts/blob/main/src/number/number.ts)\n- [`bigint`](https://github.com/ahrjarrett/any-ts/blob/main/src/number/bigint.ts)\n- [`object`](https://github.com/ahrjarrett/any-ts/blob/main/src/object/object.ts)\n- [`Path`](https://github.com/ahrjarrett/any-ts/blob/main/src/paths/Path.ts)\n- [`some`](https://github.com/ahrjarrett/any-ts/blob/main/src/some.ts)\n- [`string`](https://github.com/ahrjarrett/any-ts/blob/main/src/string/string.ts)\n- [`traversable`](https://github.com/ahrjarrett/any-ts/blob/main/src/traversable/traversable.ts)\n- [`traversal`](https://github.com/ahrjarrett/any-ts/blob/main/src/traversable/traversal.ts)\n- [`Tree`](https://github.com/ahrjarrett/any-ts/blob/main/src/tree/tree.ts)\n  - in particular, we believe our implementation of `Tree.fromPaths` to be the simplest solution + the solution with the least number of allocations possible\n- [`Union`](https://github.com/ahrjarrett/any-ts/blob/main/src/union/union.ts)\n- [`Universal`](https://github.com/ahrjarrett/any-ts/blob/main/src/universal/universal.ts)\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fahrjarrett%2Fany-ts","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fahrjarrett%2Fany-ts","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fahrjarrett%2Fany-ts/lists"}