Migration Guide
This guide helps you migrate between major versions of NeverThrow, highlighting breaking changes and how to adapt your code.Migrating to v8.0.0
Breaking Change: orElse Type Arguments
Version 8.0.0 introduces a breaking change to the orElse method to allow changing Ok types, making the types match the implementation.
What Changed:
The orElse type argument order has changed. The ok type must now be provided before the err type.
Migration Steps:
orElse callsite. If the type arguments were inferred, no updates are needed during the upgrade.
Example: Before and After
Example: Before and After
Before (v7.x):After (v8.0+):
Migrating to v7.0.0
Node.js Version Requirement
Version 7.0.0 declares the minimum supported Node.js version in theengines field.
What Changed:
- Minimum Node.js version is now declared as
>=18 - Minimum npm version is now declared as
>=11
Type Inference Improvements
Version 7.0.0 includes several type inference improvements:safeTrytype inference: Type definitions were changed to make inferring types ofsafeTrymore strictmatchtype inference: Enhanced type inference for thematchmethodcombineWithAllErrorstypes: Fixed type definitions for better error handling
Migrating from v6.x to v7.x
safeTry Return Type Change
In v7.2.0, the return type of safeTry was changed from Promise<Result<T, E>> to ResultAsync<T, E> for better composability.
What Changed:
ResultAsync is thenable and behaves like a native Promise, but provides additional methods like map, andThen, and mapErr without needing to await first.
Migration:
New Methods Added
v7.1.0 introduced new methods for handling side effects:andTee: Handle side effects on the Ok track without affecting the error typeandThrough: Similar toandTeebut propagates errors from the callbackorTee: Handle side effects on the Err track (added in v8.2.0)
Migrating from Earlier Versions
safeTry and safeUnwrap
As of v8.1.0, safeUnwrap is deprecated. When using safeTry in v8.1.0+, you no longer need to call .safeUnwrap() on results.
Before (v8.0.x and earlier):
Void Return Types
As of v8.2.0,ok, err, okAsync, and errAsync can accept zero arguments when returning void:
Version History Summary
v8.2.0 (Current)
- Added
orTeemethod for error track side effects - Allow zero arguments for void returns in
ok/err/okAsync/errAsync
v8.1.0
safeTryno longer requires.safeUnwrap()- Deprecated
safeUnwrapmethod
v8.0.0
- Breaking:
orElsetype argument order changed
v7.2.0
safeTryreturn type changed toResultAsyncfor better composability
v7.1.0
- Added
andTee,andThroughmethods - Fixed
combineWithAllErrorstypes - Improved
err()string inference
v7.0.0
- Declared minimum Node.js version (>=18)
- Improved type inference for
safeTryandmatch
Need Help?
If you encounter issues during migration:- Check the GitHub Issues
- Review the Changelog for detailed version notes
- Consult the FAQ for common questions
- Ask questions in GitHub Discussions