How to check for dayjs type with zod? #1259
-
I'm using Day.js extensively in my application. The way to check for dayjs type is to check instanceof dayjs (the function): import dayjs from "dayjs";
const date = dayjs();
console.log(date instanceof dayjs) // true The param type of const dateType = z.instanceof(dayjs as any);
How can I infer dayjs properly? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 4 replies
-
The solution didn't worked for me causing an error.
But this works: import dayjs, { type Dayjs } from 'dayjs';
...
z.instanceof(dayjs as unknown as typeof Dayjs) |
Beta Was this translation helpful? Give feedback.
-
If anyone want to haver a proper version with no type-cast: const zodDay = z.custom<Dayjs>((val) => val instanceof dayjs, 'Invalid date'); |
Beta Was this translation helpful? Give feedback.
The solution didn't worked for me causing an error.
But this works: