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
transposeAllandtransposeAnyhelpers for dealing with arrays of results. - New
fromJSONfunctions forMaybeandResultto support round-tripping. - Constraining
Maybeto 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!