You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
pipe(codec.decode(u), E.fold(() => u, codec.encode)) = u for all u in unknown
import*asassertfrom"assert";import*asEfrom"fp-ts/Either";import{pipe}from"fp-ts/function";import*astfrom"io-ts";import{optionFromNullable}from"io-ts-types";constcodec=optionFromNullable(t.string);constu=undefined;// ❌ This fails because the encode result is `null`, not `undefined`assert.strictEqual(pipe(codec.decode(u),E.fold(()=>u,codec.encode)),u);
AssertionError [ERR_ASSERTION]: Expected values to be strictly equal:
+ actual - expected
+ null
- undefined
Expected behavior
Reproducible example
See above.
Suggested solution(s)
Currently we have optionFromNullable which decodes undefined | null | T and encodes to null | T.
Perhaps we could separate this into two codecs:
optionFromOptional: decodes undefined | T and encodes to undefined | T
optionFromNullable: decodes null | T and encodes to null | T
Additional context
Your environment
Which versions of io-ts-types are affected by this issue? Did this work in previous versions of io-ts-types?
Software
Version(s)
fp-ts
io-ts
io-ts-types
TypeScript
The text was updated successfully, but these errors were encountered:
🐛 Bug report
Current Behavior
The following law as defined here:
pipe(codec.decode(u), E.fold(() => u, codec.encode)) = u
for allu
inunknown
Expected behavior
Reproducible example
See above.
Suggested solution(s)
Currently we have
optionFromNullable
which decodesundefined | null | T
and encodes tonull | T
.Perhaps we could separate this into two codecs:
optionFromOptional
: decodesundefined | T
and encodes toundefined | T
optionFromNullable
: decodesnull | T
and encodes tonull | T
Additional context
Your environment
Which versions of io-ts-types are affected by this issue? Did this work in previous versions of io-ts-types?
The text was updated successfully, but these errors were encountered: