Skip to content

Failure and success should preserve original types#255

Merged
kibertoad merged 1 commit intomainfrom
fix/preserve-type
Feb 1, 2026
Merged

Failure and success should preserve original types#255
kibertoad merged 1 commit intomainfrom
fix/preserve-type

Conversation

@kibertoad
Copy link
Collaborator

@kibertoad kibertoad commented Feb 1, 2026

Changes

Improve helper types

Checklist

  • Apply one of following labels; major, minor, patch or skip-release
  • I've updated the documentation, or no changes were necessary
  • I've updated the tests, or no changes were necessary

Summary by CodeRabbit

  • Tests

    • Added comprehensive test suite for the Either type covering success and failure paths, including type-level preservation and type guards.
  • Refactor

    • Updated generic type parameters to improve type inference and type safety.

✏️ Tip: You can customize this high-level summary in your review settings.

@kibertoad kibertoad requested review from a team, CarlosGamero and drdaemos as code owners February 1, 2026 14:18
@kibertoad kibertoad added the patch label Feb 1, 2026
@coderabbitai
Copy link

coderabbitai bot commented Feb 1, 2026

Note

.coderabbit.yaml has unrecognized properties

CodeRabbit is using all valid settings from your configuration. Unrecognized properties (listed below) have been ignored and may indicate typos or deprecated fields that can be removed.

⚠️ Parsing warnings (1)
Validation error: Unrecognized key(s) in object: 'tools'
⚙️ Configuration instructions
  • Please see the configuration documentation for more information.
  • You can also validate your configuration using the online YAML validator.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Walkthrough

The pull request adds a comprehensive unit test suite for the Either type and updates its factory functions to use const generic parameters. The tests verify both success and failure paths with proper type narrowing, while the implementation changes enhance type precision without affecting runtime behavior.

Changes

Cohort / File(s) Summary
Either Type Tests
src/errors/either.spec.ts
Adds 81 lines of comprehensive unit tests covering success path (Right), failure path (Left), type preservation for literals and objects, and type narrowing with guards.
Either Type Implementation
src/errors/either.ts
Updates failure and success factory functions to use const generic parameters (<const T> and <const U>) for improved type precision without changing runtime behavior.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and specifically describes the main change: adding const generic parameters to preserve literal types in the failure and success factory functions.
Description check ✅ Passed The description follows the required template with all sections present, though the 'Changes' section is vague ('Improve helper types' lacks specificity about what was improved and why).
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix/preserve-type

Comment @coderabbitai help to get the list of available commands and usage tips.

@kibertoad kibertoad merged commit 1224e95 into main Feb 1, 2026
7 checks passed
@kibertoad kibertoad deleted the fix/preserve-type branch February 1, 2026 14:24
@CarlosGamero
Copy link
Contributor

A bit late, but LGTM! Thanks Igor 🧡

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants