proposal: `@std/result`, a plain-object `Result<T, E>` with `tryCatch`
- Dominant language
- TypeScript
- Stars
- 3.6k
- Forks
- 681
- PR merge metrics
- No merged PRs in 30d
Description
**Is your feature request related to a problem? Please describe.**
Everyone hand-rolls the same Result type. JSR has 30+ `@*/result` packages. Theo Browne's `tryCatch` gist has 877 stars and 133 forks, each fork with a slightly different shape.
**Describe the solution you'd like**
A small, unstable `@std/result`. Plain objects, no classes, `structuredClone` and JSON safe:
```ts
type Result = { ok: true; value: T } | { ok: false; error: E };
```
Field names follow the [TC39 try operator](https://github.com/arthurfiorette/proposal-try-operator) (`ok` / `value` / `error`), so this is the future shape, not a competing one. On top: `ok`, `err`, `isOk`, `isErr`, `tryCatch`, `map`, `mapErr`, `andThen`, `unwrapOr`, `match`. That's the whole package.
No generators, no do-notation, no fluent chains. Those belong in neverthrow and Effect.
#525 turned down the Go tuple in 2019 as non-idiomatic. Agreed. A discriminated union narrows, a tuple doesn't.
Happy to open a PR if there's appetite.
**Describe alternatives you've considered**
- neverthrow, Effect, better-result: class-based, bigger, and std shouldn't bless one vendor.
- Wait for the try operator: Stage 0, no champion.
- Keep hand-rolling: the status quo, and the reason for this issue.
Contributor guide
Research direction
Start with the proposed @std/result API and its plain-object Result shape. Review the requested helpers—ok, err, isOk, isErr, tryCatch, map, mapErr, andThen, unwrapOr, and match—and confirm that the package remains small, unstable, and compatible with structuredClone and JSON.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- tooling
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Active
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100