Skip to content
Discussion options

You must be logged in to vote

@AmirL if you want to accept only one Type arg... you can do

import { z } from 'zod';

export const timestampToDate = (data: number): Date => {
    const timestamp = new Date(data);
    if (isNaN(timestamp.getTime())) {
        throw new Error('Invalid timestamp');
    }
    return timestamp;
};

export const timestampToDateSchema = z.coerce.number().transform(timestampToDate);

export const MyUsersSchema = z.array(
    z.object({
        created: timestampToDateSchema,
    })
);

// function bugExample<T>(data: unknown, schema: z.ZodType<T>) {
//     return schema.parse(data);
// }
function bugExample<ZT extends z.ZodType>(data: unknown, schema: ZT): Promise<ZT['_output']> {
    return s…

Replies: 5 comments

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Answer selected by JacobWeisenburger
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants
Converted from issue

This discussion was converted from issue #3024 on December 09, 2023 15:31.