You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Describe the bug
When validating a Date, Assert produces more than 80 lines of code. I understand that the validation mechanism is generic, but for this builtin type, could the code be reduced to if (!(a instanceof Date))?
Besides the generated code does not work with Error: Expected d.toLocaleString to be an object which should not be expected.
As Dates are not part of Json, I would understand if this is not a target for ts-runtime-checks, I'll use NoCheck<Date> on my types if that's the case.
I've always thought of Date as a class but the typescript library defines it as an interface and for that reason it's not treated as a class by the library. I'll add Date as an exception in the next patch so the code gets generated correctly!
In the meanwhile, you could use a custom Check:
type$Date=NoCheck<Date>&Check<"$self instanceof Date","to be a date">;
Describe the bug
When validating a Date, Assert produces more than 80 lines of code. I understand that the validation mechanism is generic, but for this builtin type, could the code be reduced to
if (!(a instanceof Date))
?Besides the generated code does not work with
Error: Expected d.toLocaleString to be an object
which should not be expected.As Dates are not part of Json, I would understand if this is not a target for ts-runtime-checks, I'll use
NoCheck<Date>
on my types if that's the case.Playground link
playground
Expected behavior
Date fields validate correctly
Additional context
The text was updated successfully, but these errors were encountered: