DEV Community

Discussion on: You can’t run away from runtime errors using TypeScript

Collapse
 
oculus42 profile image
Samuel Rouse

Thanks for the post! Zod looks like an interesting tool when you have strict schemas (which you really should!).

There is an error in your example in Assertions that uses typeof. typeof always returns a string.

// Current: typeof will never return Date
if(typeof data.birthDate !== Date) {

// Always use string comparisons for typeof
if (typeof data.birthDate !== 'date') {
Enter fullscreen mode Exit fullscreen mode
Collapse
 
miguelo0098 profile image
Miguelo Ramírez

Oops! Thanks for noticing that 😅

Collapse
 
oculus42 profile image
Samuel Rouse

I didn't think about that typeof returning 'object' for Dates! We should be able to use data.birthDate instanceof Date for this. 😬