Self-referential objects break decoders
See original GitHub issueIf an object is passed in that refers to itself (like the express req
object), an infinite loop occurs.
Smallest reproducible example:
const { string } = require('decoders');
// Take any decoder and pass in some self-referential object
const req = {};
req.myself = req;
console.log(string(req)); // <--- RangeError: Maximum call stack size exceeded
Issue Analytics
- State:
- Created 3 years ago
- Comments:6 (6 by maintainers)
Top Results From Across the Web
Built-in decoders
This decoder is optimized for tagged unions, i.e. a union of objects where one field is used as the discriminator. Decoding now works...
Read more >Self-Referential Classes/Linked Objects
In this lecture we will begin studying self-referential classes, which leaded to linked objects. Initially we will discuss in great detail the simplest...
Read more >Self-reference - Wikipedia
Self-reference occurs in natural or formal languages when a sentence, idea or formula refers to itself. The reference may be expressed either ...
Read more >Improving self-referential structs - language design
I'm the author of a crate called rental, designed to enable the declaration of self-borrowing structs. I've tried as hard as I could...
Read more >Managing self and cancellable references when using Combine
How to avoid common memory-related issues when working with self and cancellable references within the context of Combine.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
If you want more succinct error messages, try using
guard(..., { style: 'simple' })
instead of just the defaultguard(...)
. That will not echo back the input object, and just describe where the error is. That won’t help you with this issue, but may help reduce your error messages in case of large objects.Thanks for the good work on this library, its an essential tool when working with types in JS/TS.