True Myth now includes the
Maybe.wrapReturn function, conveniently aliased as
Maybe.ify, which lets you take any function which includes
undefined in its return type (like
Document#querySelector and friends) and convert it to a function which returns a
const querySelector = Maybe.wrapReturn(document.querySelector.bind(document)); querySelector('#neat'); // Maybe<Element>
See the docs for more!
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!
yarn upgrade true-myth@latest
npm install true-myth@latest