Wrong behavior of `mapOutput`
martinschayna opened this issue ยท 2 comments
martinschayna commented
๐ Bug report
Current Behavior
What I'm doing wrong? I've tried several examples of mapOutput
from documentation and resolved issues here, but all of them seams to be wrong too.
import * as t from "io-ts";
import { mapOutput } from "io-ts-types";
const uppercase = mapOutput(t.string, s => s.toUpperCase());
uppercase.decode("a"); // ? { _tag: "Right", right: "a" }
Expected behavior
uppercase.decode("a"); // ? { _tag: "Right", right: "A" } see "A" instead of "a"
Suggested solution(s)
I've tried to put log into the function in second argument, but it was never called. It should be called when the codec in the first argument parses input.
Your environment
"fp-ts": "2.14.0",
"io-ts": "2.2.20",
"io-ts-types": "0.5.19",
"typescript": "5.0.2",
mlegenhausen commented
The documentation clearly states that mapOutput
changes the return value of encode
not from decode
.
In your example: uppercase.encode("a") // ? "A"
martinschayna commented
Oh, I see, thank you. I am using io-ts
mainly for parsing responses from API, I always use decode
and obviously ignore the other side of codecs. My fault.