True Myth 9.1.0: Standard Schema and More!

Doing my best to keep making True Myth more useful in more places.

Assumed audience: TypeScript developers with an interest in even safer typed programming with a functional flair.

I just published v9.1.0 of True Myth: a TypeScript library that provides safe, idiomatic null, error, and async code handling, with Maybe, Result, and Task types that are really nice. The headline features for this release:

  • Standard Schema support (Guide | API Docs).
  • New transposeAll and transposeAny helpers for dealing with arrays of results.
  • New fromJSON functions for Maybe and Result to support round-tripping.
  • Constraining Maybe to accept only non-nullable types at construction, rather than only in the return types.
  • More documentation cleanup!

I think the Standard Schema integration is probably the most important of these: it means you can use True Myth’s Result and Task types transparently with the schema types from a huge swath of the TypeScript schema parsing libraries out there. (Literally A to Z with Arktype and Zod as two of the major contributors!) For a little taste of that, here’s an example of the True Myth integration:

With Arktype:

import { parserFor } from 'true-myth/standard-schema';
import { type } from 'arktype';

const personSchema = type({
  age: "number >= 0",
  "name?": "string",
});

const parsePerson = parserFor(personSchema);

With Zod:

import { parserFor } from 'true-myth/standard-schema';
import * as z from 'zod';

const personSchema = z.object({
  age: z.number().nonnegative(),
  name: z.string().optional(),
});

const parsePerson = parserFor(personSchema);

Then you can use either of those parsePerson definitions identically:

parsePerson(someUnknownData).match({
  Ok: (user) => {
    console.log(`${person.name ?? "someone"} is ${person.age} years old`);
  },
  Err: (error) => {
    console.error("Could not parse into person type:", error.issues);
  },
});

This should make True Myth that much easier to use with your favorite schema library. (This implementation may remind you of my recent note on isolatedDeclarations and Zod — and rightly so! Thinking through that gave me the push to get this done, though I had been thinking about it for a while.)

The other features are just nice quality of life improvements, but those add up. I am happy to see True Myth continuing to improve and to pick up more users across the ecosystem!