What to Call an Object Created by Zod's FormSchema `omit` Function?
Unanswered
Jersey Wooly posted this in #help-forum
Jersey WoolyOP
Excuse the triviality of the question, but I'm very fussy when it comes to naming. I'm following the official tutorial for Nextjs, Chapter 12: Mutating Data, for posting form data to a server component, and following the tutorial exactly I get this code in an
Now because the action here is a function named
actions.ts
file:import { z } from 'zod';
const FormSchema = z.object({
id: z.string(),
customerId: z.string(),
amount: z.coerce.number(),
status: z.enum(['pending', 'paid']),
date: z.string(),
});
const CreateInvoice = FormSchema.omit({ id: true, date: true });
export async function createInvoice(formData: FormData) {
const { customerId, amount, status } = CreateInvoice.parse({
customerId: formData.get('customerId'),
amount: formData.get('amount'),
status: formData.get('status'),
});
}
Now because the action here is a function named
createInvoice
, it makes me very uncomfortable to have the result of the FormSchema.omit
call named CreateInvoice
. The only operation I see used on it is parse
, I could use the name CreateInvoiceParser
, but this object can do a lot more than parsing. What suffix is apt to make this object's name a nound versus a verb?2 Replies
Greater Shearwater
I usually have the word
And then if I need the schema’s type (most of the time I do) I use the same name in PascalCase but omit the word schema.
So in this case I would call the schema
And if there was a type for it I would call it
Also I usually put all my schemas in a separate file called
schema
at the end of my schemas. And I name them in camelCase. And then if I need the schema’s type (most of the time I do) I use the same name in PascalCase but omit the word schema.
So in this case I would call the schema
createInvoiceSchema
.And if there was a type for it I would call it
CreateInvoice
.Also I usually put all my schemas in a separate file called
schemas.ts
. And export the types from it as well.@Greater Shearwater I usually have the word `schema` at the end of my schemas. And I name them in camelCase.
And then if I need the schema’s type (most of the time I do) I use the same name in PascalCase but omit the word schema.
So in this case I would call the schema `createInvoiceSchema`.
And if there was a type for it I would call it `CreateInvoice`.
Also I usually put all my schemas in a separate file called `schemas.ts`. And export the types from it as well.
Jersey WoolyOP
Thanks, that's enough for me. Just needed a nudge out of naming paralysis.