github gcanti/io-ts 2.2.12

latest releases: 2.2.20, 2.2.19, 2.2.18...
3 years ago
  • Experimental

(*) breaking change

In case of non-string tag values, the respective key must be enclosed in brackets

export const MySum: D.Decoder<
  unknown,
  | {
      type: 1 // non-`string` tag value
      a: string
    }
  | {
      type: 2 // non-`string` tag value
      b: number
    }
> = D.sum('type')({
  [1]: D.type({ type: D.literal(1), a: D.string }),
  [2]: D.type({ type: D.literal(2), b: D.number })
})

Don't miss a new io-ts release

NewReleases is sending notifications on new releases.