ts-to-io
ts-to-io copied to clipboard
Handle interface with Date property
Hi, thanks for a potentially very useful lib!
Currently, given an interface with a date property
export interface MyInterface {
myDate: Date;
}
the generated code does not compile
const MyInterface = t.type({myDate: t.type({toString: t.Function, toDateString: t.Function, toTimeString: t.Function, toLocaleString: t.Function, toLocaleDateString: t.Function, toLocaleTimeString: t.Function, valueOf: t.Function, getTime: t.Function, getFullYear: t.Function, getUTCFullYear: t.Function, getMonth: t.Function, getUTCMonth: t.Function, getDate: t.Function, getUTCDate: t.Function, getDay: t.Function, getUTCDay: t.Function, getHours: t.Function, getUTCHours: t.Function, getMinutes: t.Function, getUTCMinutes: t.Function, getSeconds: t.Function, getUTCSeconds: t.Function, getMilliseconds: t.Function, getUTCMilliseconds: t.Function, getTimezoneOffset: t.Function, setTime: t.Function, setMilliseconds: t.Function, setUTCMilliseconds: t.Function, setSeconds: t.Function, setUTCSeconds: t.Function, setMinutes: t.Function, setUTCMinutes: t.Function, setHours: t.Function, setUTCHours: t.Function, setDate: t.Function, setUTCDate: t.Function, setMonth: t.Function, setUTCMonth: t.Function, setFullYear: t.Function, setUTCFullYear: t.Function, toUTCString: t.Function, toISOString: t.Function, toJSON: t.Function, getVarDate: t.Function, __@toPrimitive: t.Function})})
Do you have any plans to support Dates?
Hi,
As far as I know there's no default codec available in io-ts for Date
objects. ts-to-io could generate a custom codec for them. However, I haven't so far decided whether to extend the project with custom codecs (which would also enable support for codecs for tuple types with rest parameters) but I'll look into it some time in the near future. One option would be to add a config flag for whether to include custom codecs if a processed type would require one.
Yes, after looking a bit closer at io-ts I understand that is the reason. It feels kind of lacking to not be able to handle dates though. That's the only 'codec' type of thing I need, otherwise I just want to use io-ts for validation. I guess DateFromISOString from https://github.com/gcanti/io-ts-types is a reasonable custom codec to use.
Let's close this one? Supporting codegen for io-ts-types
seems outside the scope of this project