fp-ts: 'evolve' Breaks w/ Partial Structs
đ Bug report
evolve, as currently defined, exhibits strange behavior re: partial fields
Current Behavior
Given:
interface A {
a?: 'a';
b?: 'b';
c?: 'c';
}
const a: A = {};
const b = F.pipe(
a,
evolve({
a: fromNullable,
b: fromNullable,
c: fromNullable,
})
);
runtime value of b = {}
Expected behavior
runtime value of b = {
a: O.none,
b: O.none,
c: O.none
}
Reproducible example
Suggested solution(s)
New implementation for evolve (keeping the same type signature)
Additional context
Originally posted by @kalda341 here
Your environment
Which versions of fp-ts are affected by this issue? Did this work in previous versions of fp-ts?
| Software | Version(s) |
|---|---|
| fp-ts | 2.11.5 |
| TypeScript | 4.5.4 |
About this issue
- Original URL
- State: open
- Created 3 years ago
- Reactions: 1
- Comments: 15 (9 by maintainers)
I think a lot of fp-ts users would agree w/ you that jsâs treatment and use of
undefinedis frustrating - thatâs why weâve avoided it in favor ofOption, and to some extent pretended it wasnât there (thus this issue)Oh wow I didnât know about âexact optional property typesâ. That could even motivate the use of
Optioninstead ofundefinedin these cases - a missing key really isnât anundefinedvalue at all. Imo that flag is proof that some developers want to treat âmissing keyâ as separate from âundefinedâMaybe it makes sense to conditionally use a type of
Option<A | undefined>orOption<A>depending on whether that property is enabled. Something like this, maybe? Playground (excludedOptionalPropertyTypes enabled), Playground (excludedOptionalPropertyTypes disabled)