{"id":13683355,"url":"https://github.com/antl3x/super-ts","last_synced_at":"2025-10-08T02:02:53.092Z","repository":{"id":57374625,"uuid":"278213821","full_name":"antl3x/super-ts","owner":"antl3x","description":"🦸 λΔ providing super powers to Typescript.","archived":false,"fork":false,"pushed_at":"2024-01-17T21:20:22.000Z","size":856,"stargazers_count":44,"open_issues_count":7,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-04-16T03:09:28.847Z","etag":null,"topics":["fantasy-land","functional-programming","haskell","purescript","static-land","typescript"],"latest_commit_sha":null,"homepage":"","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/antl3x.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-07-08T23:19:00.000Z","updated_at":"2024-02-14T02:41:53.000Z","dependencies_parsed_at":"2022-08-27T11:03:16.075Z","dependency_job_id":"d8a777e6-ea33-4a0e-9da5-520c53d6daff","html_url":"https://github.com/antl3x/super-ts","commit_stats":null,"previous_names":["nthypes/super-ts"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/antl3x%2Fsuper-ts","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/antl3x%2Fsuper-ts/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/antl3x%2Fsuper-ts/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/antl3x%2Fsuper-ts/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/antl3x","download_url":"https://codeload.github.com/antl3x/super-ts/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":251073630,"owners_count":21532010,"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":["fantasy-land","functional-programming","haskell","purescript","static-land","typescript"],"created_at":"2024-08-02T13:02:08.347Z","updated_at":"2025-10-08T02:02:48.050Z","avatar_url":"https://github.com/antl3x.png","language":"TypeScript","funding_links":[],"categories":["TypeScript"],"sub_categories":[],"readme":"# \u003cspan id=\"section:home\"\u003e🦸 λΔ super-ts\u003c/span\u003e\n\n\u003e [!WARNING]\n\u003e Hey there, just a heads-up: I've stopped updating this repo. If you're diving into functional programming—like monads, higher kinded types, and all that fun stuff—in TypeScript, you might find some handy insights here. But a little word of caution: it's probably not the best fit for production use. Happy coding!\n\n---\n\n[![npm version](https://img.shields.io/npm/v/super-ts.svg)](https://www.npmjs.com/package/super-ts)\n\n**super-ts** is a Typescript functional programming library inspired by [Haskell](https://www.haskell.org/) and [PureScript](http://www.purescript.org/) providing both runtime type checking and functional algebraic data types.\n\n**super-ts** were built to unify concepts and tools of some wonderful libraries, such _[fp-ts](https://github.com/gcanti/fp-ts)_, _[io-ts](https://github.com/gcanti/io-ts)_ and _[runtypes](https://github.com/pelotom/runtypes)_.\n\nForwarding to be an all-in-one solution, **super-ts** is divided into two main categories: **Algebraic Types** \u0026 **Runtime Types**;\n\n- _Runtime Types_: static and runtime type checking\n- _Algebraic Types_: Monads, Functors, Semigroups and others.\n\n## \u003cspan id=\"section:instalation\"\u003eInstalation\u003c/span\u003e\n\n`npm install super-ts` will install super-ts for use.\n\n## \u003cspan id=\"section:consuming\"\u003eConsuming\u003c/span\u003e\n\nYou can use **super-ts** in two flavors: CommonJS or ES Modules.\n\n```ts\nimport { String } from \"super-ts/cjs/runtime\";\nimport { Either } from \"super-ts/cjs/algebraic\";\n```\n\n```ts\nimport { String } from \"super-ts/esm/runtime\";\nimport { Either } from \"super-ts/esm/algebraic\";\n```\n\nPS: If you are using the package with ES Modules over **node** you should run your application with the flag `--experimental-specifier-resolution=node`\n\nES Modules enables [tree shaking](https://webpack.js.org/guides/tree-shaking/) to be possible using bundlers.\n\n## \u003cspan id=\"section:runtime-types\"\u003eΔ Runtime Types\u003c/span\u003e\n\n**super-ts** provides you with primitive types that can be safely type-checked at runtime with custom constraints and use this same schema as your Typescript static type signature. You can also provide custom runtime checks to build more advanced types that fit your use cases.\n\n### \u003cspan id=\"section:runtime-types-example\"\u003eΔ Why is useful?\u003c/span\u003e\n\nLet's suppose that you have the following static type schema on your Typescript project:\n\n```ts\ntype League = \"NFL\" | \"MLB\" | \"NBA\" | \"WNBA\";\n\ntype Gender = \"Male\" | \"Female\" | \"Other\";\n\ntype Team = {\n  name: string;\n  yearFounded: number;\n  league: League;\n  type: \"team\";\n};\n\ntype Player = {\n  firstName: string;\n  lastName: string;\n  salaryOnTeam: [number, Team];\n  age: number;\n  isActive: boolean;\n  teamsPlayed: Team[];\n  gender: Gender;\n  type: \"player\";\n};\n```\n\nThis works fine on TypeScript since you use this schema to type safe your application on compile time, but what about runtime? What happens if you receive this schema as a payload from some external source?\n\nIn this scenario your application is unsafe and you need to do a lot of validations to avoid runtime errors.\n\n‌To avoid all this boring work you can use **super-ts** runtime types to define your schema keeping your application safe on runtime as well on compile time, re-using static types generated by **super-ts**.\n\n### \u003cspan id=\"section:runtime-types-example\"\u003eΔ Example (Defining schema with _super-ts_)\u003c/span\u003e\n\nIn order to define the same schema as above using _super-ts_ we do the following:\n\n```ts\nimport {\n  String,\n  Number,\n  Boolean,\n  Array,\n  Record,\n  Literal,\n  Tuple,\n  Union,\n} from \"super-ts/esm/runtime\";\n\nconst League = Union(\n  Literal(\"NFL\"),\n  Literal(\"MLB\"),\n  Literal(\"NBA\"),\n  Literal(\"WNBA\")\n);\n\nconst Gender = Union(Literal(\"Male\"), Literal(\"Female\"), Literal(\"Other\"));\n\nconst Team = Record({\n  name: String,\n  yearFounded: Number,\n  league: League,\n  type: Literal(\"team\"),\n});\n\nconst Player = Record({\n  firstName: String,\n  lastName: String,\n  salaryOnTeam: Tuple(Number, Team),\n  age: Number,\n  isActive: Boolean,\n  teamsPlayed: Array(Team),\n  gender: Gender,\n  type: Literal(\"player\"),\n});\n```\n\nWhen you define your schema using **super-ts** you can get Typescript static types using the custom `TypeOf` type.\n\n```ts\nimport { TypeOf } from 'super-ts/esm/runtime'\n\ntype Player = TypeOf\u003ctypeof Player\u003e;\n\n// type Player = {\n//    firstName: string;\n//    lastName: string;\n//    salaryOnTeam: [number, {\n//        name: string;\n//        yearFounded: number;\n//        league: \"NFL\" | \"MLB\" | \"NBA\" | \"WNBA\";\n//        type: \"team\";\n//    }];\n//    age: number;\n//    isActive: boolean;\n//    teamsPlayed: {\n//        ...;\n//    }[];\n//    gender: \"Male\" | \"Female\" | \"Other\";\n//    type: \"player\";\n// }\n\n\n```\n\n### \u003cspan id=\"section:runtime-types-example\"\u003eΔ API\u003c/span\u003e\n\nWhen you use the runtime types, we expose an API under the property `.Δ` so you can use functions available for the type.\n\n#### \u003ca name=\"create\" href=\"#L512\"\u003e`check :: a -⁠\u003e Resultλ InvalidCheck a`\u003c/a\u003e\n\nTakes an unknown payload and validates against the type. If the validation suceeds,\nwe return an algebraic type called _Resultλ_ of _Sucess_ which contains the payload.\nIf the check fails we return an _Resultλ_ of _Failure_ containing an _NonEmptyArrayλ_\nof _InvalidCheck_ containing all the errors found on that payload.\n\n**Example**\n\n```ts\nimport { identity } from 'super-ts/common/identity';\nimport { Result } from 'super-ts/algebraic';\n\n/** other imports .. */\n\n/** above code .. */\n\nconst Team = Record({\n  name: String,\n  yearFounded: Number,\n  league: League,\n  type: Literal(\"team\"),\n});\n\nconst teamInvalidPayload = {\n  name: null,\n  yearFounded: \"1974\",\n  league: \"NFL\",\n  type: \"team\",\n};\n\nconst isValidTeam = Team.Δ.check(teamInvalidPayload);\n\nconst isValidTeamRes = Result.λ.fold (identity, identity) (isValidTeam);\n\n\n// isValidTeamRes = [\n//    {\n//        code: 'IS_STRING',\n//        message: 'Expected string but found (null :: object)',\n//        path: 'name'\n//    },\n//    {\n//        code: 'IS_NUMBER',\n//        message: 'Expected Number but found (1974 :: string)',\n//        path: 'yearFounded'\n//    }\n//  ]\n\n```\n\n## \u003cspan id=\"section:algebraic-types\"\u003eλ Algebraic Types\u003c/span\u003e\n\nThis documentation is working in progress.. 😅 🚧\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fantl3x%2Fsuper-ts","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fantl3x%2Fsuper-ts","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fantl3x%2Fsuper-ts/lists"}