Skip to content

literal | 字面量

literal 不能使用 coerce

ts
const tuna = z.literal("tuna");

tuna 只能匹配 "tuna"

多个子面量值

ts
const colors = z.literal(["red", "green", "blue"]);

colors.parse("green"); // ✅