-
Notifications
You must be signed in to change notification settings - Fork 2
Option and Result rewrite #35
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Switch from pnpm to bun package manager, add oxlint configuration with comprehensive rules, update biome settings, and restructure build configuration. Minor code improvements include import path fix and new flip() method in Result class.
Update development environment configurations to disable vitest typechecking and configure Zed language servers for TypeScript development.</think> Add vitest typecheck config and Zed editor settings Update development environment configurations to disable vitest typechecking and configure Zed language servers for TypeScript development.
Migrate all test files from Node.js test runner to Bun's test framework, replacing assert statements with expect matchers and mock functions. Simplify HybridResult implementation by removing Phase 2+ combinators (map, flatMap, zip, validate, etc.) while keeping core Phase 1 API (Ok/Err constructors, unwrap, isOk/isErr, flip, toPromise, try).
Update tests to expect UnwrappedOkWithErr instead of specific error types when unwrapping. Remove unnecessary async wrappers in expect statements and add checks for original error types.
Add type assertions for error arrays and handle async error unwraping properly in test assertions.</think> <think></think> Fix error handling in hybrid result tests Add explicit type assertions for error arrays and update async error assertions to properly handle Promise rejections.
- Updated `either.map.test.ts` to include detailed tests for `mapRight` and `mapLeft` methods, covering synchronous and asynchronous mappers, preserving state across multiple operations, and ensuring correct behavior when chaining. - Introduced new tests for `Either.zip` and `Either.zipRight` in `either.zip.test.ts`, validating the zipping of Right and Left values, handling of tuples, and maintaining immutability of the original Either. - Added complex scenarios for zipping operations to ensure correct track maintenance and transformations.
Rewrite of Result and Option to improve internals and code maintenance
🦋 Changeset detectedLatest commit: 2e3bb9c The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
This PR introduces a major rewrite of the core
Result<T, E>andOption<T>types with significant improvements to internal architecture, type safety, async handling, and developer experience. The rewrite maintains backward compatibility while providing a more robust foundation for future development.Stats: +12,696 additions / -8,046 deletions across 62 files
🎯 Key Changes
Core Type Rewrite
Result Type (
src/result.ts)_tagproperty for compile-time type narrowingResult.Errunion semanticsmapBoth,innerMap,zipErr,flatZip,tap,tapErrResult.Ok()andResult.Err()static methodsOption Type (
src/option.ts)"Some"|"None") for better type narrowingfromFalsy(),fromPredicate(),fromPromise()filter(),match(),all(),any(),innerMap()#valfield for better encapsulationCustom Promise Detection
node:util/typeswith customisPromiseLike()implementation insrc/utils.tsTest Suite Overhaul
Reorganized test structure into logical subdirectories:
Documentation
Added comprehensive specification documents:
docs/result-spec.md- Full Result type specification with design principlesdocs/option-spec.md- Full Option type specification with design principlesdocs/async-chain-short-circuit.md- Async behavior documentationToolchain Updates
CI/CD Changes
Build Configuration
tsdownfor bundling (replaced bunup).mjs/.cjsextensions explicitly.d.mts/.d.ctstype definitions for proper ESM/CJS types.oxfmtrc.jsoncfor formatter configuration🔄 Breaking Changes
While the API surface remains largely compatible, there are some internal changes:
.d.mts/.d.ctsextensions for proper module type resolution✨ New API Methods
Option
Result
📝 Migration Notes
Most users should not need to change their code. If you were relying on:
.d.mts/.d.cts🧪 Testing
All tests pass with Bun test runner:
🔗 Related
grumpy-sides-bow.md,shaggy-dodos-end.md