Should zod schema names start with an uppercase letter or not?

What is the general guideline for naming zod schemas. In the docs there seem to be examples using capitalized names as well as lowercase names, thus I was wondering what naming convention the community decided upon. This example uses lowecase userSchema:
import { z } from "zod";

// creating a schema for strings
const mySchema = z.string();

// parsing
mySchema.parse("tuna"); // => "tuna"
mySchema.parse(12); // => throws ZodError

// "safe" parsing (doesn't throw error if validation fails)
mySchema.safeParse("tuna"); // => { success: true; data: "tuna" }
mySchema.safeParse(12); // => { success: false; error: ZodError }
import { z } from "zod";

// creating a schema for strings
const mySchema = z.string();

// parsing
mySchema.parse("tuna"); // => "tuna"
mySchema.parse(12); // => throws ZodError

// "safe" parsing (doesn't throw error if validation fails)
mySchema.safeParse("tuna"); // => { success: true; data: "tuna" }
mySchema.safeParse(12); // => { success: false; error: ZodError }
Whereas this one uses uppercase User:
import { z } from "zod";

const User = z.object({
username: z.string(),
});

User.parse({ username: "Ludwig" });

// extract the inferred type
type User = z.infer<typeof User>;
// { username: string }
import { z } from "zod";

const User = z.object({
username: z.string(),
});

User.parse({ username: "Ludwig" });

// extract the inferred type
type User = z.infer<typeof User>;
// { username: string }
12 Replies
Neto
Neto•2y ago
there is no rule about it just do what looks right for you
tawaliou
tawaliou•2y ago
Like @nyx (Rustular DevRel) said, just do what you want but keep consistent... If you choose upper keep it don't miss with lower
barry
barry•2y ago
Doesn't matter
Keef
Keef•2y ago
I just stick to the usual consensus around objects but am very tempted to start prefixing them with z like "zUser" to better highlight they are kinda different sorta like type names being TUser
barry
barry•2y ago
not a thing anymore we don' do that
Keef
Keef•2y ago
nyx has shilled it to me I STOPPED DOING IT THEN NYX CONVINCED ME AGAIN AND NOW ITS OUT OF FASHION 😭
barry
barry•2y ago
nyx bozo aint no body call a counter variable an intCounter either
Keef
Keef•2y ago
eh ugly emoji BETTER
Neto
Neto•2y ago
who is a theowat
Neto
Neto•2y ago
ok pleb
Keef
Keef•2y ago
Look at them with their white name
Want results from more Discord servers?
Add your server