All notable changes to this project will be documented in this file.
The format is based on Keep a Changelog and this project adheres to Semantic Versioning.
- #756 Forbid
null
andundefined
as arguments toMaybe.just
(@chriskrycho)
- Chris Krycho (@chriskrycho)
- #755 Correctly handle
null
andundefined
in function return types (@chriskrycho)
- #754 infra: update to actions/checkout@v4 for GHA (@chriskrycho)
- Chris Krycho (@chriskrycho)
- #749 Allow readonly Arrays in
find()
(@screendriver) - #720 Add (tested) support for Node 20 (@chriskrycho)
- #719 Add support for TypeScript 5.4 (@chriskrycho)
- #650 Add support for TypeScript 5.3 (@dependabot[bot])
- #751 Supply an
AnyArray
type in maybe.ts (@chriskrycho) - #750 infra: update to latest pnpm (@chriskrycho)
- #631 Simplify CI test matrix (@chriskrycho)
- Chris Krycho (@chriskrycho)
- Christian Rackerseder (@screendriver)
- #609 Add support for TypeScript 5.2 (@chriskrycho)
- #572 Fix docs for
transposeArray
(@chriskrycho)
- #601 refactor: Remove duplicate tests in '/test/result.test.ts' (@royiro10)
- #585 Further work to fix pnpm usage in TS nightly (@chriskrycho)
- #584 More cleanup: pnpm references and prettierignore (@chriskrycho)
- #583 Fix CI for nightly TS run (@chriskrycho)
- Chris Krycho (@chriskrycho)
- @royiro10
- #570 Fix CJS import location in package
exports
map (@chriskrycho)
- #569 Fix docs publishing GH Action (@chriskrycho)
- Chris Krycho (@chriskrycho)
- #562 [Breaking] Require Node 18, adopt pnpm, use latest release-it (@chriskrycho)
- #567 Publish True Myth as a dual-mode package (ESM + CJS) (@chriskrycho)
- #561 Add type-safe
Ok.cast()
andErr.cast()
methods (@chriskrycho) - #552 Add support for TypeScript 5.0 and 5.1 (@dependabot[bot])
- #469 Add support for TypeScript 4.9 (@dependabot[bot])
- #568 Upgrade to latest TypeDoc (@chriskrycho)
- #566 Use pnpm in CI (@chriskrycho)
- Chris Krycho (@chriskrycho)
- Josh Martinez (@jm4rtinez)
- @DaviDevMod
- #438 Add explicit support for TS 4.8 (@chriskrycho)
- #437 docs: include doc comments in published types (@chriskrycho)
- #437 docs: include doc comments in published types (@chriskrycho)
- #434 Update readme with v6.x requirements (@bmakuh)
- #436 chore: remove defunct parts of package (@chriskrycho)
- Ben Makuh (@bmakuh)
- Chris Krycho (@chriskrycho)
- Re-export
Toolbelt
from root for consumers not using TS 4.7’sexports
support (@chriskrycho)
- #388 Remove v5 CI configuration (@chriskrycho)
- Chris Krycho (@chriskrycho)
There are two significant breaking changes in v6.0:
- It now requires TypeScript 4.7+ and Node 14+. This allows us to use Node's
exports
syntax without hacks. - It removes items deprecated in the 4.x and 5.x cycles. This allows us to provide better tree-shaking. Previously, using either the
Result
orMaybe
classes meant you also pulled in the other, since they had code to interoperate with each other. These now live only in thetoolbelt
module, along with theArray
helpers.
To upgrade:
-
Update your project to at least Node 14 and TypeScript 4.7.
-
Switch from using any deprecated code to the supported replacements (as described in the docs for each deprecated function).
-
Set
compilerOptions.module
toNode16
ornodenext
in yourtsconfig.json
. Note: this is the most significant breaking change here: it requires that every other TS package you consume also be compatible with the new mode, and if you are using True Myth in a library, cascades that requirement to your consumers as well. -
Update to True Myth v6. 🎉
- #357 Update publication mechanics with "exports" (@chriskrycho)
- #352 Update minimum Node to v14, add v18 (@chriskrycho)
- #252 Enable tree-shaking by removing deprecated code (@chriskrycho)
- #242 Improve performance by switching to a 'methods-first' implementation (@chriskrycho)
- #360 Decrease Unit implementation runtime size (@chriskrycho)
- #356 Improve
toString
handling (forward-port from v5) (@chriskrycho) - #351 More forward ports (@chriskrycho)
- #275 One fewer assignment in Nothing construction (@chriskrycho)
- #252 Enable tree-shaking by removing deprecated code (@chriskrycho)
- #251 [Forward] Deprecate Maybe.head for 6.0, preferring Maybe.first (@chriskrycho)
- #250 [Forward] Deprecate non-Toolbelt versions of toolbelt utils (@chriskrycho)
- #249 [Forward] Introduce
true-myth/toolbelt
module for better tree shaking (@chriskrycho) - #242 Improve performance by switching to a 'methods-first' implementation (@chriskrycho)
- #351 More forward ports (@chriskrycho)
- #276 Finish forward-porting null/undefined reversion (@chriskrycho)
- #274 Forward port more fixes (@chriskrycho)
- 5.1.1 regression: type inference for Result.ok (@krivachy)
- #387 Prep for v6 release (@chriskrycho)
- #383 Incorporate TS 4.7 and next in support matrix (@chriskrycho)
- #355 Update the CHANGELOG and
package.json
to actual current (@chriskrycho) - #350 Improve doc comments on Maybe and Toolbelt (@chriskrycho)
- #317 Forward-port CI, docs updates (@chriskrycho)
- #267 [Forward] Fix out-of-date parts of README (@chriskrycho)
- #387 Final updates (@chriskrycho)
- #386 Drop
preversion
npm script (@chriskrycho) - #384 Simplify
exports
definitions for types (@chriskrycho) - #383 Incorporate TS 4.7 and next in support matrix (@chriskrycho)
- #377 Add option to run Nightly TS run manually (@chriskrycho)
- #376 Use 'Node16' to support TS 4.7 (@chriskrycho)
- #362 Add Code of Conduct and Contributing guide (@chriskrycho)
- #359 Actually run yarn so TypeDoc is available (@chriskrycho)
- #358 Switch docs publishing to use gh-pages on release (@chriskrycho)
- #353 Use
Omit
rather thanExclude
+keyof
in Maybe (@chriskrycho) - #354 Use
Omit
rather thanExclude
+keyof
in Maybe (@chriskrycho) - #264 [Forward] no ESLint (@chriskrycho)
- #242 Improve performance by switching to a 'methods-first' implementation (@chriskrycho)
- Akos Krivachy (@krivachy)
- Chris Krycho (@chriskrycho)
This is the final release for v5.x, and only exists to make sure there are fully overlapping supported TypeScript versions for True Myth v5 and v6. See the release notes for the upcoming v6.0 release for upgrade notes.
- #382 v5.x: Add Node 18 and TS 4.7 (@chriskrycho)
- #385 v5.x: Drop
preversion
npm script (@chriskrycho) - #361 Add conduct and contributing (v5.x) (@chriskrycho)
- #354 Use
Omit
rather thanExclude
+keyof
in Maybe (@chriskrycho)
- Chris Krycho (@chriskrycho)
- #336 Require narrowing before exposing wrapped values (@screendriver)
- Christian Rackerseder (@screendriver)
- #349 Add support for TypeScript 4.7 (@chriskrycho)
- #334 Export pure isErr() function (@screendriver)
- #332 Export pure isNothing() function (@screendriver)
- #333 Export pure isOk() function (@screendriver)
- #331 Export pure isJust() function (@screendriver)
- #335 Add missing readonly variants modifiers (@screendriver)
- Chris Krycho (@chriskrycho)
- Christian Rackerseder (@screendriver)
- #299 feat(maybe/find): type narrowing via predicates (@buschtoens)
- Jan Buschtöns (@buschtoens)
- Luc Boissaye (@ombr)
- #272 Fix v5 regression of checks on
.value
(@chriskrycho) - #273 Revert handling of explicit
null
andundefined
(@chriskrycho)
- #266 Fix out-of-date parts of README (@chriskrycho)
- Chris Krycho (@chriskrycho)
- #263 Fix regression of
Result.ok()
(@chriskrycho)
- #263 Fix regression of
Result.ok()
(@chriskrycho)
- #262 Remove ESLint (@chriskrycho)
- #253 Target both
main
andnext
with Dependabot (@chriskrycho)
- Chris Krycho (@chriskrycho)
- #248 Deprecate Maybe.head for 6.0, preferring Maybe.first (@chriskrycho)
- #247 Deprecate non-Toolbelt versions of toolbelt utils (@chriskrycho)
- #246 Introduce
true-myth/toolbelt
module for better tree shaking (@chriskrycho)
- Chris Krycho (@chriskrycho)
- #243 Add
package.json
toexports
(@chriskrycho)
- #226 Export useful internal types, improve docs (@chriskrycho)
- Chris Krycho (@chriskrycho)
-
The top-level namespace-style export has been removed. If you were relying on the static members to be present when doing
import Maybe from 'true-myth/maybe'
orimport Result from 'true-myth/result';
, you can replace them withimport * as Maybe from 'true-myth/maybe';
orimport * as Result from 'true-myth/result';
. This should make for much better tree-shaking with bundlers like Rollup, which can see “through” a namespace import in a way they cannot with a manually-created namespace object. Where you want to maintain the type and namespace imports, you can do this:import * as Maybe from 'true-myth/maybe'; type Maybe<T> = Maybe.Maybe<T>; // convenience alias
In general, though, you should prefer to simply import the named functions instead:
import Maybe, { transposeArray } from 'true-myth/maybe';
-
There are no longer separate classes for
Just
,Nothing
,Ok
, andErr
. This substantially reduces the size of the library, and should hopefully improve browsers' ability to optimize code using these, since there is now only one class in each case:Maybe
andResult
. The public API for the classes is unchanged, but if you relied oninstanceof
checks against those classes anywhere, those checks will no longer work. -
The exported
Variant
types are now frozen, constant objects, not TypeScriptenum
s. This should not break anyone, since the only difference in observable behavior between anenum
and aconst
is the ability to do a “reverse lookup” on anenum
—but since the field names and their values are identical, this just means shipping less, and faster, code. -
The
isJust
,isNothing
,isOk
, andisErr
methods have been converted to getters. This makes them muchmore immediately useful in contexts where invoking a function is annoying, for any reason—for example, in Ember templates. -
We no longer publish CommonJS modules, only ES Modules.
-
Dropped support for Node versions earlier than Node 12 LTS.
-
Support for versions of TypeScript before 4.0 have been removed, to enable the type-safe re-implementation of
Maybe.all
. -
The
MaybeShape
andResultShape
interfaces are no longer exported. These were never intended for public reimplementation, and there is accordingly no value in their continuing to be public. -
A number of aliases (originally designed to make migration from e.g. Folktale easier) have been removed:
cata
: usematch
chain
andflatMap
: useandThen
maybeify
andtransmogrify
: usewrapReturn
unsafelyGet
andunsafeGet
: use.isJust
/.isOk
then.value
unsafelyGetErr
andunsafelyUnwrapErr
: use.isErr
then.error
getOr
: useunwrapOr
getOrElse
: useunwrapOrElse
fromNullable
andmaybe
:- import
Maybe
and use its static constructorMaybe.of
- import the module as namespace and use
Maybe.of
- import
of
and alias it as you like
- import
-
We introduced a new
Maybe.transposeArray
, which is a type-safe, renamed, merged version ofMaybe.tuple
andMaybe.all
which can correctly handle both array and tuple types. To support this change, it now accepts arrays or tuples directly, and the variadic/spread arguments toall
have been replaced with taking an array or tuple directly. Whiletuple
andall
are unchanged, they are also deprecated (see below).Before:
import Maybe, { all, just, nothing, tuple } from 'true-myth/maybe'; // arrays type ArrayResult = Maybe<Array<string | number>>; let mixedArray = [just("hello"), nothing<number>()]; let mixedArrayResult: ArrayResult = all(...arrayOfMaybes); let allJustArray = [just("hello"), just(12)]; let allJustArrayResult: ArrayResult = all(...allJustArray); type Tuple = [Maybe<number>, Maybe<string>]; type TupleResult = Maybe<[number, string]>; let mixedTuple: Tuple = [just(12), just("hi")]; let mixedTupleResult: TupleResult = tuple(mixedTuple);
After:
import Maybe, { arrayTranspose, just, nothing } from 'true-myth/maybe'; // arrays type ArrayResult = Maybe<Array<string | number>>; let mixedArray = [just("hello"), nothing<number>()]; let mixedArrayResult: ArrayResult = arrayTranspose(arrayOfMaybes); let allJustArray = [just("hello"), just(12)]; let allJustArrayResult: ArrayResult = arrayTranspose(allJustArray); // Tuples now work with `arrayTranspose` as well. type Tuple = [Maybe<number>, Maybe<string>]; type TupleResult = Maybe<[number, string]>; let mixedTuple: Tuple = [just(12), just("hi")]; let mixedTupleResult: TupleResult = arrayTranspose(mixedTuple);
-
Maybe.transpose
andResult.transpose
: for when you have aMaybe<Result<T, E>>
or aResult<Maybe<T>, E>
and need to invert them.import Maybe, { just, nothing } from 'true-myth/maybe'; import Result, { ok, err } from 'true-myth/result'; let anOkJust: Result<Maybe<number>, string> = ok(just(12)); let maybe: Maybe<number>, string> = Maybe.transposeResult(anOkJust); console.log(maybe); // Just(Ok(12)) let aJustOk: Maybe<Result<number, string>> = just(ok(12)); let result: Maybe<Result<number, string>> = Result.transposeMaybe(aJustOk); console.log(result); // Ok(Just(12))
See the docs for further details!
Note: these are standalone functions, not methods, because TypeScript does not support conditionally supplying a method only for one specific type parameterization.
Maybe.tuple
andMaybe.all
are deprecated in favor ofMaybe.arrayTranspose
now correctly handles both arrays and tuples. They will be removed not earlier than 6.0.0 (timeline not decided, but not sooner than when Node 12 LTS reaches end of life on April 30, 2022).
4.1.1 (2021-01-31)
- Set
stripInternal
to false for generated types (#97), so that they type-check.
4.1.0 (2020-12-13)
- Support unwrapping to an alternative type with (backwards-compatible) tweak to type of
Maybe.unwrapOr
andResult.unwrapOr
. For example, givenlet a: Maybe<string>
,let b = a.unwrapOr(42)
would produce a type ofstring | number
forb
. Useful particularly for interop withnull
andundefined
at system boundaries while preserving general type safety.
- @alantrick (#69)
- @C-Saunders, @flyiniggle, @bmakuh, @atrick-speedline (#63, discussion motivating #69)
4.0.0 (2019-12-18)
- Switched to using namespace-style imports (
import * as Maybe
) internally to enable users to tree-shake.
- Explicitly drop support for Node 8 (and specify it going forward)
- Reverted the use of
NonNullable
to constraint the types of callbacks like that passed tomap
andmapOr
, because they broke in TypeScript 3.6. (If you have ideas about how to improve this, please let us know!)
With yarn:
yarn upgrade true-myth@latest
With npm:
npm install true-myth@latest
- @chriskrycho
- @bmakuh
3.1.0 (2019-10-08)
Thanks to @MarcNq, with very helpful input from @CrossEye, True Myth now has toJSON
functions and methods on its types. This means that there's now a stable serialization format, which you can rely on going forward!
For Maybe<T>
, the type is { variant: 'Just', value: T }
or { variant: 'Nothing' }
. For Result
, it's { variant: 'Ok', value: T }
or { variant: 'Err', error: E }
. Since we just hand back the wrapped item, any object's implementation of toJSON
or similar will work as usual, so you're fully in control of serialization.
With yarn:
yarn upgrade true-myth@latest
With npm:
npm install true-myth@latest
- @MarcNq
- @CrossEye
- @chriskrycho
- @bmakuh
3.0.0 (2019-05-17)
True Myth now includes the Maybe.wrapReturn
function, conveniently aliased as maybeify
and Maybe.ify
, which lets you take any function which includes null
or undefined
in its return type (like Document#querySelector
and friends) and convert it to a function which returns a Maybe
instead:
const querySelector = Maybe.wrapReturn(document.querySelector.bind(document));
querySelector('#neat'); // Maybe<Element>
See the docs for more!
All Maybe
helper functions must now return NonNullable<T>
. This example, which previously compiled and resulted in the type Maybe<string | null>
, will now cause a type error:
Maybe.of(document.querySelector('#neat'))
.map(el => el.style.color); // `color` may be `null`
SemVer note: The new behavior was the ordinary expectation for those types before—doing otherwise would cause a runtime error—and so could reasonably be described as a bugfix. Any place this type-checked before was causing a runtime error. However, it seems clearer simply to mark it as a breaking change, since it may cause your build to fail, and encourage you all to upgrade directly and fix those bugs if so!
With yarn:
yarn upgrade true-myth@latest
With npm:
npm install true-myth@latest
- @bmakuh
- @chriskrycho
- @snatvb