Skip to content

Latest commit

 

History

History
543 lines (366 loc) · 28.1 KB

CHANGELOG.md

File metadata and controls

543 lines (366 loc) · 28.1 KB

Changelog

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.

7.3.0 (2024-05-26)

🚀 Enhancement

Committers: 1

7.2.1 (2024-05-26)

🐛 Bug Fix

  • #755 Correctly handle null and undefined in function return types (@chriskrycho)

🏠 Internal

Committers: 1

7.2.0 (2024-05-16)

🚀 Enhancement

🏠 Internal

Committers: 2

7.1.0 (2023-09-05)

🚀 Enhancement

📝 Documentation

🏠 Internal

Committers: 2

7.0.1 (2023-07-16)

🐛 Bug Fix

🏠 Internal

Committers: 1

7.0.0 (2023-07-15)

💥 Breaking Change

  • #562 [Breaking] Require Node 18, adopt pnpm, use latest release-it (@chriskrycho)

🚀 Enhancement

📝 Documentation

🏠 Internal

Committers: 3

6.2.0 (2022-09-08)

🚀 Enhancement

🐛 Bug Fix

📝 Documentation

🏠 Internal

Committers: 2

6.1.0 (2022-07-08)

🚀 Enhancement

  • Re-export Toolbelt from root for consumers not using TS 4.7’s exports support (@chriskrycho)

🏠 Internal

Committers: 1

6.0.0 (2022-05-25)

There are two significant breaking changes in v6.0:

  1. It now requires TypeScript 4.7+ and Node 14+. This allows us to use Node's exports syntax without hacks.
  2. 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 or Maybe classes meant you also pulled in the other, since they had code to interoperate with each other. These now live only in the toolbelt module, along with the Array helpers.

To upgrade:

  1. Update your project to at least Node 14 and TypeScript 4.7.

  2. Switch from using any deprecated code to the supported replacements (as described in the docs for each deprecated function).

  3. Set compilerOptions.module to Node16 or nodenext in your tsconfig.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.

  4. Update to True Myth v6. 🎉

💥 Breaking Change

🚀 Enhancement

🐛 Bug Fix

📝 Documentation

🏠 Internal

Committers: 2

5.4.0 (2022-05-25)

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.

🚀 Enhancement

🏠 Internal

Committers: 1

5.3.1 (2022-04-22)

🐛 Bug Fix

Committers: 1

5.3.0 (2022-04-22)

🚀 Enhancement

🐛 Bug Fix

Committers: 2

5.2.0 (2022-03-07)

🚀 Enhancement

Committers: 1

5.1.3 (2022-03-06)

🐛 Bug Fix

Committers: 1

5.1.2 (2021-12-27)

🐛 Bug Fix

📝 Documentation

Committers: 1

5.1.1 (2021-12-16)

🚀 Enhancement

🐛 Bug Fix

🏠 Internal

Committers: 1

5.1.0 (2021-12-12)

🚀 Enhancement

Committers: 1

5.0.1 (2021-12-11)

🐛 Bug Fix

📝 Documentation

Committers: 1

💥 Changed

  • 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' or import Result from 'true-myth/result';, you can replace them with import * as Maybe from 'true-myth/maybe'; or import * 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, and Err. 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 and Result. The public API for the classes is unchanged, but if you relied on instanceof checks against those classes anywhere, those checks will no longer work.

  • The exported Variant types are now frozen, constant objects, not TypeScript enums. This should not break anyone, since the only difference in observable behavior between an enum and a const is the ability to do a “reverse lookup” on an enum—but since the field names and their values are identical, this just means shipping less, and faster, code.

  • The isJust, isNothing, isOk, and isErr 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 and ResultShape 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: use match
    • chain and flatMap: use andThen
    • maybeify and transmogrify: use wrapReturn
    • unsafelyGet and unsafeGet: use .isJust/.isOk then .value
    • unsafelyGetErr and unsafelyUnwrapErr: use .isErr then .error
    • getOr: use unwrapOr
    • getOrElse: use unwrapOrElse
    • fromNullable and maybe:
      • import Maybe and use its static constructor Maybe.of
      • import the module as namespace and use Maybe.of
      • import of and alias it as you like

⭐ Added

  • We introduced a new Maybe.transposeArray, which is a type-safe, renamed, merged version of Maybe.tuple and Maybe.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 to all have been replaced with taking an array or tuple directly. While tuple and all 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 and Result.transpose: for when you have a Maybe<Result<T, E>> or a Result<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.

🟥 Deprecated

  • Maybe.tuple and Maybe.all are deprecated in favor of Maybe.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)

🔧 Fixed

  • Set stripInternal to false for generated types (#97), so that they type-check.

4.1.0 (2020-12-13)

⭐ Added

  • Support unwrapping to an alternative type with (backwards-compatible) tweak to type of Maybe.unwrapOr and Result.unwrapOr. For example, given let a: Maybe<string>, let b = a.unwrapOr(42) would produce a type of string | number for b. Useful particularly for interop with null and undefined at system boundaries while preserving general type safety.

🙇 Contributors

  • @alantrick (#69)
  • @C-Saunders, @flyiniggle, @bmakuh, @atrick-speedline (#63, discussion motivating #69)

4.0.0 (2019-12-18)

🔧 Fixed

  • Switched to using namespace-style imports (import * as Maybe) internally to enable users to tree-shake.

💥 Changed

  • 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 to map and mapOr, because they broke in TypeScript 3.6. (If you have ideas about how to improve this, please let us know!)

⚙️ Upgrading

With yarn:

yarn upgrade true-myth@latest

With npm:

npm install true-myth@latest

🙇 Contributors

  • @chriskrycho
  • @bmakuh

3.1.0 (2019-10-08)

⭐ Added

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.

⚙️ Upgrading

With yarn:

yarn upgrade true-myth@latest

With npm:

npm install true-myth@latest

🙇 Contributors

  • @MarcNq
  • @CrossEye
  • @chriskrycho
  • @bmakuh

3.0.0 (2019-05-17)

⭐ 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

  • @bmakuh
  • @chriskrycho
  • @snatvb