Skip to content

Instantly share code, notes, and snippets.

@hastebrot
Last active May 20, 2025 14:11
Show Gist options
  • Save hastebrot/9505698bae4cef5fd5d105092fb6bb77 to your computer and use it in GitHub Desktop.
Save hastebrot/9505698bae4cef5fd5d105092fb6bb77 to your computer and use it in GitHub Desktop.
type NonEmptyArray<T> = [T, ...T[]];
const okay: NonEmptyArray<number> = [1, 2];
const alsoOkay: NonEmptyArray<number> = [1];
const err: NonEmptyArray<number> = []; // error!
import { z } from "zod/v4";
const Foo = z.string().array().nonempty();
type Foo = z.infer<typeof Foo>;
const NonEmpty = z.tuple([z.string()], z.string());
type NonEmpty = z.infer<typeof NonEmpty>;
const array = Foo.parse([]);
console.log(array);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment