Last active
May 20, 2025 14:11
-
-
Save hastebrot/9505698bae4cef5fd5d105092fb6bb77 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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