io-ts
io-ts copied to clipboard
from partial to require
with the experimental codec API, how do we set default values for partials?
import * as codec from "io-ts/Codec";
interface In {
folder?: boolean;
}
interface Out {
folder: boolean;
}
// how to turn this to be Out type?
const innn = codec.partial({
folder: codec.boolean
})
You could use imap
import { pipe, identity } from 'fp-ts/function'
const c: codec.Codec<unknown, In, Out> = pipe(
innn,
codec.imap(({ folder }) => ({ folder: folder ?? false }), identity)
)
Awesome. I did try this, but I what I'm really after is a combinator where the codec is used to.
I'll try out some kind and report back for the masses.