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.

`coerce()` should run recursively (and not assert)

See original GitHub issue

Right now, it’s impossible to coerce a nested structure, both because coerce() also validates (#467 ) but also because coerce() only runs on the top-level object. For instance, coerce({}, type({...props})) will fail, even if all props have coercions, because they never run.

coerce() should function parallel to check() (preferably with a context object). In the case of validate-with-coerce, they could still run like now, in tandem.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:2
  • Comments:10 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
mikestopcontinuescommented, Mar 24, 2021

Ah, I’m sorry. I lost the thread a little. I think this probably deserves a bug report. I’d you look at the code, type is definitely supposed to be recursive. I can say I’ve found union to be a little finicky myself, so I’d be willing to be the problem is there.

1reaction
nhagencommented, Mar 24, 2021

But does it work recursively? I’m running into an issue where its not validating nested structures, resulting in

Expected the value to satisfy a union of type | type, but received: [object Object]"

Not sure if its a bug I should make an example for, or if create is not intended to be recursive for type objects as mentioned earlier in this thread

I’ll try to check more directly today to see if I can answer my own question. Read this thread and assumed it wasn’t supported.

Read more comments on GitHub >

github_iconTop Results From Across the Web

performance - Recursion or Iteration? - Stack Overflow
If your recursive method takes longer to execute then the calling context management part, go the recursive way as the code is generally...
Read more >
Why use a recursive function instead of an iterative function?
An assignment had us convert an iterative function in an old program from a previous assignment into a recursive function. I don't understand ......
Read more >
AssertJ - fluent assertions java library - GitHub Pages
Setting comparators must be done before calling the assertion otherwise it is ignored as a failing assertion breaks will prevent the call to...
Read more >
Documentation - TypeScript 3.7
asserts condition says that whatever gets passed into the condition parameter must be true if the assert returns (because otherwise it would throw...
Read more >
Recursion and linked lists - CS 2112/ENGRD 2112 Fall 2019
This recursive definition not only makes sense mathematically, ... For recursive code to be correct, the base case of the recursion must eventually...
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