I missed Go's `if err != nil`, so I built errval for TypeScript
Description and use
errval returns an [err, value] tuple, providing explicit error indication, type safety, and exhaustive case handling, improving reliability in TypeScript.
Problem
TypeScript developers lack explicit error handling like Go’s if err != nil, leading to ambiguous catch (e) blocks and runtime errors.
Outcome
errval provides explicit error tuples, inferred error unions, and exhaustive matching, improving type safety and reducing runtime errors. Benchmarks show comparable performance to neverthrow and far better than try/catch on failure paths.
Workflow
- 1. Call an async function that returns
[err, value]viaawait getUser(id). 2. Checkif (err)and handle or return early. 3. Use the value safely without!or type assertions. 4. Handle errors withmatch(err, {NotFound:..., Forbidden:..., DbError:...})ensuring all cases compile. - 5. Add new error types in services; the handler’s
matchwill fail to compile until a case is added.
Evidence
I benchmarked it. A request handler where half the requests fail, Node 24.16, per request: neverthrow: 198 ns, errval: 226 ns, try/catch: 2,623 ns
Return a new error type from the service and the match in the handler will stop compiling until it has a case for it.
- Record date: 2026-09-22T02:45:38.986Z