Skip to content

@chriskrycho chriskrycho released this May 17, 2019 · 3 commits to master since this release

Added ⭐️

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!

Changed 💥

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!

Upgrading ⚙️

With yarn:

yarn upgrade true-myth@latest

With npm:

npm install true-myth@latest

Contributors 🙇

Assets 2
You can’t perform that action at this time.