Pertinate
Pertinate
TTCTheo's Typesafe Cult
Created by Pertinate on 11/11/2023 in #questions
Generic Zod Type without defining generics?
at the bottom, te doesn't know the given return for parse
3 replies
TTCTheo's Typesafe Cult
Created by Pertinate on 11/11/2023 in #questions
Generic Zod Type without defining generics?
type Methods = 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE';
type RouteType = 'client' | 'server';

interface Route<T extends RouteType> {
type: T;
path: T extends 'client' ? ClientPath : ServerPath;
method: T extends 'client' ? 'GET' : Methods;
}

export type ClientPath = '/page' | '/:user/:productId';

type ClientRoute = Route<'client'> & {
schema?: {
paramSchema?: z.Schema;
querySchema?: z.Schema;
};
};
export const clientRoutes: readonly ClientRoute[] = [
{
type: 'client',
path: '/:user/:productId',
method: 'GET',
schema: {
paramSchema: z.record(z.union([z.literal('user'), z.literal('productId')]), z.string())
}
},
{
type: 'client',
path: '/page',
method: 'GET',
},
] as const;

const te = clientRoutes[0].schema?.paramSchema?.parse({})
type Methods = 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE';
type RouteType = 'client' | 'server';

interface Route<T extends RouteType> {
type: T;
path: T extends 'client' ? ClientPath : ServerPath;
method: T extends 'client' ? 'GET' : Methods;
}

export type ClientPath = '/page' | '/:user/:productId';

type ClientRoute = Route<'client'> & {
schema?: {
paramSchema?: z.Schema;
querySchema?: z.Schema;
};
};
export const clientRoutes: readonly ClientRoute[] = [
{
type: 'client',
path: '/:user/:productId',
method: 'GET',
schema: {
paramSchema: z.record(z.union([z.literal('user'), z.literal('productId')]), z.string())
}
},
{
type: 'client',
path: '/page',
method: 'GET',
},
] as const;

const te = clientRoutes[0].schema?.paramSchema?.parse({})
3 replies
TTCTheo's Typesafe Cult
Created by Pertinate on 12/8/2022 in #questions
Issues with next-auth discord
thank you!
25 replies
TTCTheo's Typesafe Cult
Created by Pertinate on 12/8/2022 in #questions
Issues with next-auth discord
will try later
25 replies