BASE

neverthrow

neverthrow

Backend / API library · Free

Typed Result and ResultAsync for TypeScript: they make expected errors an explicit part of a function's return value.

Also known as: supermacro/neverthrow; type-safe-errors

Resource illustration: neverthrow

Open resource ↗

What you can use for free

Code and local use under MIT.

Paid features and costs

Computing resources, self-hosting, and external services are paid for separately if used.

Access and limitations

Code and local use under MIT. Computing resources, self-hosting, and external services are paid for separately if used.

Use cases

  • Make an expected error part of the result
  • Connect Result/ResultAsync composition to error handling by calling code

Example workflow

A possible workflow; this is not a report of hands-on testing.

Make an expected error part of the result.

Before you start

  • A data contract or HTTP workflow.
  • A project with a supported runtime.

Steps

  1. Define success/error types for the backend operation.
  2. Connect Result/ResultAsync composition to error handling by calling code.
  3. Add error handling and an integration check of the result.

Check your result

  • Invalid and missing data are handled predictably.
  • Types and the actual response agree; errors are not hidden.

Choosing neverthrow

Make an expected error part of the result

Choose this when

  • Make an expected error part of the result
  • Connect Result/ResultAsync composition to error handling by calling code

Things to consider

  • Costs and limits of free use: Computing resources, self-hosting, and external services are paid for separately if used.
  • Terms of use: MIT for the code; dependencies have separate licenses.
  • fromSafePromise does not convert rejection to Err; use it only for a genuinely safe Promise. The name neverthrow does not guarantee that third-party code will not throw exceptions.

Frequently asked questions

What can you use for free in neverthrow?

Code and local use under MIT.

What additional costs might arise with neverthrow?

Computing resources, self-hosting, and external services are paid for separately if used.

What terms of use matter for neverthrow?

MIT for the code; dependencies have separate licenses.

How do you get started with neverthrow?

Define success/error types for the backend operation. Connect Result/ResultAsync composition to error handling by calling code. Add error handling and an integration check of the result.

How does ResultAsync differ from Promise, and does it catch every throw?

Result/ResultAsync represent success and errors as typed values. map/mapErr transform branches, andThen composes operations, combine returns the first error, and combineWithAllErrors returns all errors. fromPromise handles rejection of an already created Promise; a synchronous throw while calling a function before creating it requires fromThrowable.

License

MIT for the code; dependencies have separate licenses.

MIT — permissive license

You can use, modify, distribute, and sell the code, including in a closed-source commercial product. When sharing copies or substantial portions of the code, retain the license text and copyright notice. You do not need to open-source your entire project; the author provides no warranties.

License terms

Technologies and topics

  • neverthrow
  • API
  • Development

Sources

Other resources