Skip to main content

tuple

Creates a schema that validates a tuple of values. An optional rest schema can be passed to validate the rest of the values.

Example​

import { tuple, number, object, string, boolean } from "@sodd/core";

const coordinatesSchema = tuple([number(), number()]);
coordinatesSchema.parse([1, 2]);
// ✅ => [1, 2];

// examples are hard
const weirdSchema = tuple([boolean(), object({ name: string() })], number());
weirdSchema.parse([true, { name: "Test McTestface" }, 1, 2, 3, 4]);
// ✅ => [true, { name: "Test McTestface" }, 1, 2, 3, 4];

Issue types​