{"id":25344744,"url":"https://github.com/iyegoroff/ts-railway","last_synced_at":"2026-03-01T05:34:44.522Z","repository":{"id":57381052,"uuid":"308630125","full_name":"iyegoroff/ts-railway","owner":"iyegoroff","description":"ROP flavoured Result \u0026 AsyncResult types","archived":false,"fork":false,"pushed_at":"2023-08-14T23:31:33.000Z","size":2047,"stargazers_count":13,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-10-26T02:51:34.659Z","etag":null,"topics":["railway-oriented-programming","result"],"latest_commit_sha":null,"homepage":"https://iyegoroff.github.io/ts-railway/index.html","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/iyegoroff.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-10-30T12:53:54.000Z","updated_at":"2025-01-10T10:38:05.000Z","dependencies_parsed_at":"2024-06-19T11:28:52.562Z","dependency_job_id":"feaeb812-d125-43ed-8479-5342feb3b376","html_url":"https://github.com/iyegoroff/ts-railway","commit_stats":{"total_commits":160,"total_committers":1,"mean_commits":160.0,"dds":0.0,"last_synced_commit":"640e321d78de51b37163f4c219ab3491c804aa4c"},"previous_names":[],"tags_count":44,"template":false,"template_full_name":null,"purl":"pkg:github/iyegoroff/ts-railway","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/iyegoroff%2Fts-railway","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/iyegoroff%2Fts-railway/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/iyegoroff%2Fts-railway/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/iyegoroff%2Fts-railway/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/iyegoroff","download_url":"https://codeload.github.com/iyegoroff/ts-railway/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/iyegoroff%2Fts-railway/sbom","scorecard":{"id":499098,"data":{"date":"2025-08-11","repo":{"name":"github.com/iyegoroff/ts-railway","commit":"640e321d78de51b37163f4c219ab3491c804aa4c"},"scorecard":{"version":"v5.2.1-40-gf6ed084d","commit":"f6ed084d17c9236477efd66e5b258b9d4cc7b389"},"score":2.9,"checks":[{"name":"Code-Review","score":0,"reason":"Found 0/30 approved changesets -- score normalized to 0","details":null,"documentation":{"short":"Determines if the project requires human code review before pull requests (aka merge requests) are merged.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#code-review"}},{"name":"Dangerous-Workflow","score":10,"reason":"no dangerous workflow patterns detected","details":null,"documentation":{"short":"Determines if the project's GitHub Action workflows avoid dangerous patterns.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#dangerous-workflow"}},{"name":"Maintained","score":0,"reason":"0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0","details":null,"documentation":{"short":"Determines if the project is \"actively maintained\".","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#maintained"}},{"name":"Packaging","score":-1,"reason":"packaging workflow not detected","details":["Warn: no GitHub/GitLab publishing workflow detected."],"documentation":{"short":"Determines if the project is published as a package that others can easily download, install, easily update, and uninstall.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#packaging"}},{"name":"SAST","score":0,"reason":"no SAST tool detected","details":["Warn: no pull requests merged into dev branch"],"documentation":{"short":"Determines if the project uses static code analysis.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#sast"}},{"name":"Token-Permissions","score":0,"reason":"detected GitHub workflow tokens with excessive permissions","details":["Warn: no topLevel permission defined: .github/workflows/build.yml:1","Warn: no topLevel permission defined: .github/workflows/publish.yml:1","Info: no jobLevel write permissions found"],"documentation":{"short":"Determines if the project's workflows follow the principle of least privilege.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#token-permissions"}},{"name":"Binary-Artifacts","score":10,"reason":"no binaries found in the repo","details":null,"documentation":{"short":"Determines if the project has generated executable (binary) artifacts in the source repository.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#binary-artifacts"}},{"name":"CII-Best-Practices","score":0,"reason":"no effort to earn an OpenSSF best practices badge detected","details":null,"documentation":{"short":"Determines if the project has an OpenSSF (formerly CII) Best Practices Badge.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#cii-best-practices"}},{"name":"Pinned-Dependencies","score":3,"reason":"dependency not pinned by hash detected -- score normalized to 3","details":["Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/build.yml:9: update your workflow using https://app.stepsecurity.io/secureworkflow/iyegoroff/ts-railway/build.yml/main?enable=pin","Warn: third-party GitHubAction not pinned by hash: .github/workflows/build.yml:14: update your workflow using https://app.stepsecurity.io/secureworkflow/iyegoroff/ts-railway/build.yml/main?enable=pin","Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/build.yml:17: update your workflow using https://app.stepsecurity.io/secureworkflow/iyegoroff/ts-railway/build.yml/main?enable=pin","Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/publish.yml:15: update your workflow using https://app.stepsecurity.io/secureworkflow/iyegoroff/ts-railway/publish.yml/main?enable=pin","Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/publish.yml:16: update your workflow using https://app.stepsecurity.io/secureworkflow/iyegoroff/ts-railway/publish.yml/main?enable=pin","Info:   0 out of   4 GitHub-owned GitHubAction dependencies pinned","Info:   0 out of   1 third-party GitHubAction dependencies pinned","Info:   1 out of   1 npmCommand dependencies pinned"],"documentation":{"short":"Determines if the project has declared and pinned the dependencies of its build process.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#pinned-dependencies"}},{"name":"Security-Policy","score":0,"reason":"security policy file not detected","details":["Warn: no security policy file detected","Warn: no security file to analyze","Warn: no security file to analyze","Warn: no security file to analyze"],"documentation":{"short":"Determines if the project has published a security policy.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#security-policy"}},{"name":"Fuzzing","score":0,"reason":"project is not fuzzed","details":["Warn: no fuzzer integrations found"],"documentation":{"short":"Determines if the project uses fuzzing.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#fuzzing"}},{"name":"License","score":10,"reason":"license file detected","details":["Info: project has a license file: LICENSE:0","Info: FSF or OSI recognized license: MIT License: LICENSE:0"],"documentation":{"short":"Determines if the project has defined a license.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#license"}},{"name":"Signed-Releases","score":-1,"reason":"no releases found","details":null,"documentation":{"short":"Determines if the project cryptographically signs release artifacts.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#signed-releases"}},{"name":"Branch-Protection","score":0,"reason":"branch protection not enabled on development/release branches","details":["Warn: branch protection not enabled for branch 'main'"],"documentation":{"short":"Determines if the default and release branches are protected with GitHub's branch protection settings.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#branch-protection"}},{"name":"Vulnerabilities","score":2,"reason":"8 existing vulnerabilities detected","details":["Warn: Project is vulnerable to: GHSA-968p-4wvh-cqc8","Warn: Project is vulnerable to: GHSA-67hx-6x53-jw92","Warn: Project is vulnerable to: GHSA-v6h2-p8h4-qcjw","Warn: Project is vulnerable to: GHSA-grv7-fg5c-xmjg","Warn: Project is vulnerable to: GHSA-3xgq-45jj-v275","Warn: Project is vulnerable to: GHSA-952p-6rrq-rcjv","Warn: Project is vulnerable to: GHSA-c2qf-rxjj-qqgw","Warn: Project is vulnerable to: GHSA-j8xg-fqg3-53r7"],"documentation":{"short":"Determines if the project has open, known unfixed vulnerabilities.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#vulnerabilities"}}]},"last_synced_at":"2025-08-19T21:20:32.242Z","repository_id":57381052,"created_at":"2025-08-19T21:20:32.242Z","updated_at":"2025-08-19T21:20:32.242Z"},"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29960434,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-03-01T01:47:18.291Z","status":"online","status_checked_at":"2026-03-01T02:00:07.437Z","response_time":124,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"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":["railway-oriented-programming","result"],"created_at":"2025-02-14T11:50:59.396Z","updated_at":"2026-03-01T05:34:44.488Z","avatar_url":"https://github.com/iyegoroff.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# ts-railway\n\n[![npm](https://img.shields.io/npm/v/ts-railway)](https://npm.im/ts-railway)\n[![build](https://github.com/iyegoroff/ts-railway/workflows/build/badge.svg)](https://github.com/iyegoroff/ts-railway/actions/workflows/build.yml)\n[![publish](https://github.com/iyegoroff/ts-railway/workflows/publish/badge.svg)](https://github.com/iyegoroff/ts-railway/actions/workflows/publish.yml)\n[![codecov](https://codecov.io/gh/iyegoroff/ts-railway/branch/main/graph/badge.svg?t=1520230083925)](https://codecov.io/gh/iyegoroff/ts-railway)\n[![Type Coverage](https://img.shields.io/badge/dynamic/json.svg?label=type-coverage\u0026prefix=%E2%89%A5\u0026suffix=%\u0026query=$.typeCoverage.atLeast\u0026uri=https%3A%2F%2Fraw.githubusercontent.com%2Fiyegoroff%2Fts-railway%2Fmain%2Fpackage.json)](https://github.com/plantain-00/type-coverage)\n![Libraries.io dependency status for latest release](https://img.shields.io/librariesio/release/npm/ts-railway/6.1.4)\n[![bundlejs](https://deno.bundlejs.com/?q=ts-railway@6.1.4,ts-railway@6.1.4\u0026treeshake=[*],[{+default+}]\u0026badge=)](https://bundlejs.com/?q=ts-railway)\n[![npm](https://img.shields.io/npm/l/ts-railway.svg?t=1495378566925)](https://www.npmjs.com/package/ts-railway)\n\nROP flavoured Result \u0026 AsyncResult types. Based on [Railway oriented programming](https://fsharpforfunandprofit.com/posts/recipe-part2/) article by Scott Wlaschin.\n\n## Getting started\n\n`$ npm i ts-railway`\n\n## Overview\n\n### Main types\n\n- [`SuccessResult\u003cSuccess\u003e`](./src/types.ts#L1) - represents a success with an associated value of `Success` type\n- [`FailureResult\u003cFailure\u003e`](./src/types.ts#L6) - represents a failure with an associated value of `Failure` type\n- [`Result\u003cSuccess, Failure\u003e`](./src/types.ts#L12) - a union of `SuccessResult` and `FailureResult`\n- [`AsyncResult\u003cSuccess, Failure\u003e`](./src/types.ts#L20) - a `Result` wrapped in `Promise`\n- [`SomeResult\u003cSuccess, Failure\u003e`](./src/types.ts#L22) - a union of `Result` and `AsyncResult`\n\n---\n\n### Functions\n\nAll mapping functions have at least two overloaded signatures - common `(transform, result) =\u003e new_result` and curried `(transform) =\u003e (result) =\u003e new_result`. Curried form is intended to be used with some piping function (e.g. [pipe-ts](https://npm.im/pipe-ts)).\n\n|               | Result                                   | AsyncResult                                          |\n| ------------- | ---------------------------------------- | ---------------------------------------------------- |\n| success       | [↗️](./mds/result.md#resultsuccess)      | 🚫                                                   |\n| failure       | [↗️](./mds/result.md#resultfailure)      | 🚫                                                   |\n| map           | [↗️](./mds/result.md#resultmap)          | [↗️](./mds/async-result.md#asyncresultmap)           |\n| mapError      | [↗️](./mds/result.md#resultmaperror)     | [↗️](./mds/async-result.md#asyncresultmaperror)      |\n| flatMap       | [↗️](./mds/result.md#resultflatmap)      | [↗️](./mds/async-result.md#asyncresultflatmap)       |\n| flatMapError  | [↗️](./mds/result.md#resultflatmaperror) | [↗️](./mds/async-result.md#asyncresultflatmaperror)  |\n| mapAsync      | 🚫                                       | [↗️](./mds/async-result.md#asyncresultmapasync)      |\n| mapAsyncError | 🚫                                       | [↗️](./mds/async-result.md#asyncresultmapasyncerror) |\n| match         | [↗️](./mds/result.md#resultmatch)        | [↗️](./mds/async-result.md#asyncresultmatch)         |\n| combine       | [↗️](./mds/result.md#resultcombine)      | [↗️](./mds/async-result.md#asyncresultcombine)       |\n\n---\n\n## Usage\n\n### Avoiding 'pyramid of doom'\n\nComposing several functions with multiple arguments can be cumbersome and will lead to 'pyramid of doom' style of code:\n\n```typescript\nconst div = (a: number, b: number) /*: Result\u003cnumber, 'div by zero'\u003e */ =\u003e\n  b === 0 ? Result.failure('div by zero' as const) : Result.success(a / b)\n\nconst result = Result.map(\n  (x: string) =\u003e [...x].reverse().join(''),\n  Result.map(\n    (x: number) =\u003e `${x}`,\n    Result.map(\n      (x: number) =\u003e x + 234,\n      Result.mapError(\n        (x: 'div by zero') =\u003e ({ divError: x } as const),\n        Result.map((x) =\u003e x * 2, div(500, 1))\n      )\n    )\n  )\n)\n\nexpect(result).toEqual({\n  tag: 'success',\n  success: '4321'\n})\n```\n\nThis can be easily avoided when using curried forms of functions with a piping function:\n\n```typescript\nimport { pipeWith } from 'pipe-ts'\n\nconst result = pipeWith(\n  div(500, 1),\n  Result.mapError((x) =\u003e ({ divError: x } as const)),\n  Result.map((x) =\u003e x * 2),\n  Result.map((x) =\u003e x + 234),\n  Result.map((x) =\u003e `${x}`),\n  Result.map((x) =\u003e [...x].reverse().join(''))\n)\n\nexpect(result).toEqual\u003ctypeof result\u003e({\n  tag: 'success',\n  success: '4321'\n})\n```\n\n---\n\n### Programming style\n\nThere are certain [catches](https://fsharpforfunandprofit.com/posts/against-railway-oriented-programming/) of railway\noriented programming. Most of them are matter of program design quality. But in the context of TypeScript language,\nthe most serious problem is the ability to completely discard the result of a function call ([TypeScript/#8240](https://github.com/microsoft/TypeScript/issues/8240), [TypeScript/#8584](https://github.com/microsoft/TypeScript/issues/8584)). For example, in the following\nsnippet possible parsing error will be discarded:\n\n```typescript\ndeclare const obj: {\n  parse: \u003cT\u003e(json: string) =\u003e Result\u003cT, Error\u003e\n}\n\nfunction foo() {\n  obj.parse('][') // Result is discarded!\n}\n\nfoo()\n```\n\nMore sneaky error:\n\n```typescript\ndeclare function updateUser(info: { name: string }): AsyncResult\u003cundefined, Error\u003e\n\ndeclare const MyButton: {\n  onClick: () =\u003e void\n}\n\nMyButton.onClick(\n  () =\u003e updateUser({ name: 'username' }) // AsyncResult is covered with void and discarded!\n)\n```\n\nThese kind of problems can be minimized by using proper project configuration: setting `\"strict\": true` in `tsconfig`,\nprohibiting expression statements with `functional/no-expression-statement` rule from [eslint-plugin-functional](https://npm.im/eslint-plugin-functional) and banning `void` type with `@typescript-eslint/ban-types` rule\nfrom [@typescript-eslint/eslint-plugin](https://npm.im/@typescript-eslint/eslint-plugin). [tsconfig.json](./tsconfig.json) and [.eslintrc](./.eslintrc) files from this project could be used as a starting point.\n\n---\n\n### Exception handling\n\n`ts-railway` is intended to handle only [domain errors](https://fsharpforfunandprofit.com/posts/against-railway-oriented-programming/#when-should-you-use-result) and doesn't catch thrown exceptions and unhandled promise rejections. The common scenario to deal\nwith exceptions is to catch them globally, log somehow and then decide whether to prevent an exception by fixing/changing the\nprogram or to convert that exception to domain error:\n\n```typescript\nconst errorHandler: OnErrorEventHandlerNonNull = (event) =\u003e {\n  MyLoggingService.log(event)\n}\n\nwindow.onerror = errorHandler\nwindow.onunhandledrejection = errorHandler\n```\n\n---\n\n### 'Ecosystem'\n\nSome packages compatible with `ts-railway`:\n\n- [spectypes](https://github.com/iyegoroff/spectypes) - fast, compiled, eval-free data validator/transformer\n- [fetchmap](https://github.com/iyegoroff/fetchmap) - non-throwing fetch wrapper\n- [ts-elmish](https://github.com/iyegoroff/ts-elmish) - elmish architecture in typescript\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fiyegoroff%2Fts-railway","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fiyegoroff%2Fts-railway","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fiyegoroff%2Fts-railway/lists"}