Bug on custom type inference? Maybe I'm doing something wrong.

export const timez = customType<
{
data: Date;
driverData: string;
config: { precision?: number };
}
>({
dataType(config) {
const precision = typeof config?.precision !== 'undefined'
? ` (${config.precision})`
: '';
return `time${precision} with time zone`;
},
fromDriver(value: string): Date {
return new Date(value);
},
});
export const timez = customType<
{
data: Date;
driverData: string;
config: { precision?: number };
}
>({
dataType(config) {
const precision = typeof config?.precision !== 'undefined'
? ` (${config.precision})`
: '';
return `time${precision} with time zone`;
},
fromDriver(value: string): Date {
return new Date(value);
},
});
Then if I:
endTime: timez("end_time"),

// I get from inference

type Type = {
endTime?: any;
}
endTime: timez("end_time"),

// I get from inference

type Type = {
endTime?: any;
}
The type on endTime should be Date not any I'm using drizzle-orm 0.28.5
6 Replies
dandadan
dandadan•15mo ago
same issue
Guilherme Rosado
Guilherme RosadoOP•15mo ago
I fixed it by
export const timestampz = (field: string) => timestamp(field, { withTimezone: true });
export const timez = (field: string) => time(field, { withTimezone: true });
export const timestampz = (field: string) => timestamp(field, { withTimezone: true });
export const timez = (field: string) => time(field, { withTimezone: true });
But yeah 😦 If you can submit the bug on gh
dandadan
dandadan•15mo ago
i assume you were using drizzle-zod? my issue was there, but inferring the types directly from the table gives the correct type type x = table.$inferSelect like this
const schema = createSelectSchema(table);
type x = z.infer<typeof schema>;
const schema = createSelectSchema(table);
type x = z.infer<typeof schema>;
this doesnt though
Guilherme Rosado
Guilherme RosadoOP•15mo ago
Huh this is actually working for me I do this all the time
Guilherme Rosado
Guilherme RosadoOP•15mo ago
No description
Guilherme Rosado
Guilherme RosadoOP•15mo ago
the createSchemaParse is a method that I created
Want results from more Discord servers?
Add your server