Use satisfies operator for type validation instead of explicit types#424
Closed
Use satisfies operator for type validation instead of explicit types#424
Conversation
- 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 Report✅ All modified and coverable lines are covered by tests. 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. 🚀 New features to boost your workflow:
|
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
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
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
Refactored type annotations to use TypeScript's
satisfiesoperator instead of explicit type declarations. This approach provides better type inference while still maintaining type safety.Key Changes
satisfiesclause, allowing the object literal to maintain its inferred type while still validating against the expected interfacesatisfies Record<string, string>to theas constassertion for better type validationsatisfies Record<string, number>to theas constassertion for better type validationImplementation Details
The
satisfiesoperator validates that a value conforms to a type without widening or narrowing the inferred type. This is particularly beneficial for:https://claude.ai/code/session_017ckt1JVw39ymzvu2gRxpBS