char
char
TTCTheo's Typesafe Cult
Created by char on 11/10/2023 in #questions
computed properties in zod
my api returns an object with dates as the key - is this possible to model in zod?
const response = {
"2023-11-10": <value>,
"2023-11-11": <value>
}
const response = {
"2023-11-10": <value>,
"2023-11-11": <value>
}
something like:
const schema = z.object({
[z.string()]: <value>
})
const schema = z.object({
[z.string()]: <value>
})
3 replies
TTCTheo's Typesafe Cult
Created by char on 2/7/2023 in #questions
Is there a way to create "const objects" from zod?
Im looking to create an object of default values, and an object of literals to use as an enum:
export const homeAddressFormSchema = z.object({
clientHomeAddressLine1: z.string().min(1).optional(),
clientHomeAddressLine2: z.string().min(1).optional(),
clientHomeCity: z.string().min(1).optional(),
clientHomeState: z.string().min(1).optional(),
clientHomeZipCode: z.string().min(1).optional(),
});

export type HomeAddressFormData = z.infer<typeof homeAddressFormSchema>;



// object of literals I'm trying to extract from zod schema
export const HomeAddressConst = {
clientHomeAddressLine1: 'clientHomeAddressLine1',
clientHomeAddressLine2: 'clientHomeAddressLine2',
clientHomeCity: 'clientHomeCity',
clientHomeState: 'clientHomeState',
clientHomeZipCode: 'clientHomeZipCode',
} as const;

// object of initial values I'm trying to extract from zod schema
const initialHomeAddressFormData: HomeAddressFormData = {
clientHomeAddressLine1: undefined,
clientHomeAddressLine2: undefined,
clientHomeCity: undefined,
clientHomeState: undefined,
clientHomeZipCode: undefined,
};
export const homeAddressFormSchema = z.object({
clientHomeAddressLine1: z.string().min(1).optional(),
clientHomeAddressLine2: z.string().min(1).optional(),
clientHomeCity: z.string().min(1).optional(),
clientHomeState: z.string().min(1).optional(),
clientHomeZipCode: z.string().min(1).optional(),
});

export type HomeAddressFormData = z.infer<typeof homeAddressFormSchema>;



// object of literals I'm trying to extract from zod schema
export const HomeAddressConst = {
clientHomeAddressLine1: 'clientHomeAddressLine1',
clientHomeAddressLine2: 'clientHomeAddressLine2',
clientHomeCity: 'clientHomeCity',
clientHomeState: 'clientHomeState',
clientHomeZipCode: 'clientHomeZipCode',
} as const;

// object of initial values I'm trying to extract from zod schema
const initialHomeAddressFormData: HomeAddressFormData = {
clientHomeAddressLine1: undefined,
clientHomeAddressLine2: undefined,
clientHomeCity: undefined,
clientHomeState: undefined,
clientHomeZipCode: undefined,
};
context is this is setup for a form
3 replies
TTCTheo's Typesafe Cult
Created by char on 2/1/2023 in #questions
What's everyone using for implementing google sso?
We have a vite app where we manage user sessions in a django backend - need to replace react-google-login. Open to suggestions!
7 replies
TTCTheo's Typesafe Cult
Created by char on 1/26/2023 in #questions
Does anyone here use graphQL + trpc?
At first this might seem like a silly question considering they're always positioned as pick one or the other, but in our system we use graphql for some greenfield reads and REST for some GETS + writes Our backend is in django, and we mostly use nextJS for its frontend. Was wondering if the decision to combine the 2 would sound dumb since we could still benefit from parsing the data we get back from graphql/our django backend with zod + get "E2E types" in the FE
9 replies
TTCTheo's Typesafe Cult
Created by char on 11/25/2022 in #questions
Best practices or course on writing a production-grade NextJS backend?
Hey all! I've spent most of my career in the frontend so I'm pretty familiar with React. Recently I was able to get buy in for migrating our Express backend to Nextjs after watching Theo's Next Conf + it not really ever making sense that we have a separate backend to begin with. I was wondering if anyone had recommendations for courses or readings on how to organize a Nextjs backend, with naming convention, proper error handling, custom middlewares (not using nextjs' middleware.ts), how to organize a backend project along with scripts, integrating with third party services like queues etc thank you!
9 replies