Skip to content

v8.1.0

Latest
Compare
Choose a tag to compare
@DZakh DZakh released this 29 Aug 16:54
· 120 commits to main since this release

🆕 Tag shorthand for Js/Ts api object schema

Besides passing schemas for values in S.object, you can also pass any Js value.

const meSchema = S.object({
  id: S.number,
  name: "Dmitry Zakharov",
  age: 23,
  kind: "human" as const,
  metadata: {
    description: "What?? Even an object with NaN works! Yes 🔥",
    money: NaN,
  },
});

This is a shorthand for the advanced s.tag and useful for discriminated unions.

// TypeScript type for reference:
// type Shape =
// | { kind: "circle"; radius: number }
// | { kind: "square"; x: number }
// | { kind: "triangle"; x: number; y: number };

const shapeSchema = S.union([
  S.object({
    kind: "circle" as const,
    radius: S.number,
  }),
  S.object({
    kind: "square" as const,
    x: S.number,
  }),
  S.object({
    kind: "triangle" as const,
    x: S.number,
    y: S.number,
  }),
]);

Full Changelog: v8.0.3...v8.1.0