Skip to content

Use satisfies operator for type validation instead of explicit types#424

Closed
gjbkz wants to merge 2 commits intomainfrom
claude/explain-zod-readme-7NfDo
Closed

Use satisfies operator for type validation instead of explicit types#424
gjbkz wants to merge 2 commits intomainfrom
claude/explain-zod-readme-7NfDo

Conversation

@gjbkz
Copy link
Member

@gjbkz gjbkz commented Feb 19, 2026

Summary

Refactored type annotations to use TypeScript's satisfies operator instead of explicit type declarations. This approach provides better type inference while still maintaining type safety.

Key Changes

  • typeCheckerConfig: Moved type annotation from explicit object type to satisfies clause, allowing the object literal to maintain its inferred type while still validating against the expected interface
  • HttpMethod: Added satisfies Record<string, string> to the as const assertion for better type validation
  • HttpStatusCode: Added satisfies Record<string, number> to the as const assertion for better type validation

Implementation Details

The satisfies operator validates that a value conforms to a type without widening or narrowing the inferred type. This is particularly beneficial for:

  • Configuration objects where we want to preserve the literal types of individual properties
  • Enum-like objects where we want to maintain precise type information while ensuring structural correctness
  • Better IDE autocomplete and type inference for consumers of these exports

https://claude.ai/code/session_017ckt1JVw39ymzvu2gRxpBS

- HttpMethod and HttpStatusCode const objects now use `as const satisfies Record<string, string/number>` to validate value types at compile time while preserving literal types for ValueOf<> unions
- typeCheckerConfig switches from explicit type annotation to satisfies, preserving the concrete inferred type while still validating the shape

https://claude.ai/code/session_017ckt1JVw39ymzvu2gRxpBS
@codecov
Copy link

codecov bot commented Feb 19, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 96.86%. Comparing base (cae2eb5) to head (ebcac9d).

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #424   +/-   ##
=======================================
  Coverage   96.86%   96.86%           
=======================================
  Files          45       45           
  Lines        2104     2104           
  Branches      209      209           
=======================================
  Hits         2038     2038           
  Misses         66       66           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

JSR's slow-type checker requires explicit type annotations on all
exported symbols. The previous satisfies-based changes broke this in
two ways:
- as const satisfies T disables JSR's special as-const inlining
- replacing a : T annotation with satisfies T removes the explicit type

Revert all three changes to restore TestPublish CI.

https://claude.ai/code/session_017ckt1JVw39ymzvu2gRxpBS
@gjbkz gjbkz closed this Feb 19, 2026
@gjbkz gjbkz deleted the claude/explain-zod-readme-7NfDo branch February 19, 2026 00:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

Comments