I'm aware of io-ts but I haven't jumped on the fp-ts bandwagon yet. The learning curve seems quite steep.
The decoder you just mentioned would fail at compile-time, because number and string are different types.
If the data you want to decode is a number but you want a string you could do:
Have you seen io-ts? io-ts also removes the duplication by creating a "decoder" and a type at the same time.
what would happen in this case?
I'm aware of io-ts but I haven't jumped on the fp-ts bandwagon yet. The learning curve seems quite steep.
The decoder you just mentioned would fail at compile-time, because
number
andstring
are different types.If the data you want to decode is a
number
but you want astring
you could do:Cheers!