Types
Never
If you need a codec that is never valid, you can use ft.Never. You might use this as the type for an API endpoint that's not yet implemented and so you don't want it to ever be called.
import * as ft from "funtypes";
const MySchema = ft.Never;
// => ft.Codec<never>
type MyType = ft.Static<typeof MySchema>;
// => never
// 🚨 Never will always throw when you try to parse something
assert.throws(() => MySchema.parse({}));
If you use ft.Never inside a Union, it's effectively removed from the list of possibilities.
import * as ft from "funtypes";
const MyUnion = ft.Union(
ft.String,
ft.Never,
);
// => ft.Codec<string>
type MyType = ft.Static<typeof MySchema>;
// => string
// ✅ Can parse the other types in the union
assert.deepEqual(
MySchema.parse("Hello World"),
"Hello World",
);