TaggedError requirement
#237
Problem— I would open this as a discussion, but this repo has disabled discussions tab. First, thank you so much for the effort you've put in this library. It looks great at a glance! I wonder if the usage of Proposed solutionI think a better interoperability with the user's existing errors could greatly increase this library's adoption. Alternatives consideredNo response Scope check
|
Replies: 1 comment 1 reply
|
Thanks for the kind words, and for asking — this was a fair thing to be unsure about. Confirming: And the modelled/unexpected split you were reaching for is not done by the error’s shape at all: it is The docs led you to think otherwise, though, which is on us — so #236 fixes the framing and adds a runnable example ( 👉 #236 |
Thanks for the kind words, and for asking — this was a fair thing to be unsure about.
Confirming:
TaggedErroris not a requirement.Result<T, E>is generic inEand unconstrained — there is noE extends { _tag: string }anywhere in core, andP.tag("X")is only sugar for the object pattern{ _tag: "X" }, one pattern among several. Your existing error types work as-is: match on akind/codefield with an object pattern, on an untagged class withP.instanceOf, on anything else withP.when. The only real requirement is thatEis a union TypeScript can discriminate, since exhaustiveness isExcludeover it — the same thing aswitchneeds.And the modelled/unexpected split you were reaching for…