Open ForbesLindesay opened 3 years ago
Draft implementation: #17
A side effect of this change is that we are also effectively deep cloning everything, which takes care of https://github.com/pelotom/runtypes/issues/132 and https://github.com/pelotom/runtypes/issues/24 (remove unknown keys from validated object). It may be worth looking into supporting a fast path that doesn't clone objects if none of the validations change anything.
The types in
io-ts
are actually "Codecs": https://github.com/gcanti/io-ts/blob/master/index.md#the-ideaWhat this means is that they support having different runtime types on the "serialized" end (where they are typically of type
unknown
in TypeScript) and the "parsed" end. This can be useful for:{objectWithLongKeys: number}
could become a tuple[number]
when serialized){version: 1, size: number} | {version: 2, width: number, height: number}
but only want to deal with version 2 in your app)We're actually in a pretty good place to support this. Our primative Runtype has a
validate
method with the perfect signature to act asparse
.Requested in https://github.com/pelotom/runtypes/issues/56