Closed gcanti closed 5 years ago
createOptionFromJSON should handle the following encoding
createOptionFromJSON
type JSONOption<A> = { _tag: 'None' } | { _tag: 'Some'; value: A }
createEitherFromJSON should handle the following encoding
createEitherFromJSON
type JSONEither<L, A> = { _tag: 'left', value: L } | { _tag: 'Right'; value: A }
These changes would allow handy roundtrips when using JSON.stringify
JSON.stringify
import * as assert from 'assert' import { right } from 'fp-ts/lib/Either' const testRoundtrip = <A>(codec: t.Type<A>) => { const OptionFromJSON = createOptionFromJSON(codec) return (ma: Option<A>) => { const result = OptionFromJSON.decode(JSON.parse(JSON.stringify(ma))) assert.deepStrictEqual(result, right(ma)) } } const test = testRoundtrip(t.number) test(none) test(some(1))
https://github.com/gcanti/io-ts-types/pull/86
createOptionFromJSON
should handle the following encodingcreateEitherFromJSON
should handle the following encodingThese changes would allow handy roundtrips when using
JSON.stringify