question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. ItĀ collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

'evolve' Breaks w/ Partial Structs

See original GitHub issue

šŸ› 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

TS Playground

Suggested solution(s)

New implementation for evolve (keeping the same type signature)

TS Playground

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

Issue Analytics

  • State:open
  • Created 2 years ago
  • Reactions:1
  • Comments:15 (9 by maintainers)

github_iconTop GitHub Comments

1reaction
anthonyjoesephcommented, Feb 3, 2022

I think a lot of fp-ts users would agree w/ you that js’s treatment and use of undefined is frustrating - that’s why we’ve avoided it in favor of Option, 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 Option instead of undefined in these cases - a missing key really isn’t an undefined value 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> or Option<A> depending on whether that property is enabled. Something like this, maybe? Playground (excludedOptionalPropertyTypes enabled), Playground (excludedOptionalPropertyTypes disabled)

0reactions
anthonyjoesephcommented, Feb 28, 2022

That’s great, I’m glad you like them! Ok it sounds like we have

Just a note: this already exists for Eq, inside the module io-ts. Maybe ā€˜semigroup’ and ā€˜monoid’ also belong there? Although it’s hard to see how those are ā€˜decoding’ or ā€˜encoding’ values in a runtime type system

Read more comments on GitHub >

github_iconTop Results From Across the Web

Possibility to makes classes/structs partial as C# language
C# language allows developers to make its classes partial . It is possible to split the definition of class, struct or interface over...
Read more >
Double-Strand DNA Breaks | Learn Science at Scitable - Nature
The genome of a cell is continuously damaged, which is inevitable because DNA damage often arises as a result of normal cellular processes....
Read more >
Long-time evolution of interfacial structure of partial wetting
Abstract. When a solid plate is withdrawn from a partially wetting liquid, a liquid layer dewets the moving substrate. High-speed imagingĀ ...
Read more >
Regulation of Error-Prone DNA Double-Strand Break Repair ...
To deal with these breaks, cells have evolved a variety of robust and ... These secondary structures serve as primers for limited DNAĀ ......
Read more >
Partial Dislocation - an overview | ScienceDirect Topics
A partial dislocation glides on the slip plane, and a stacking fault arises ... The SFE of metals and alloys with fcc crystal...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found