-
-
Notifications
You must be signed in to change notification settings - Fork 6
feat: add const type parameter to isLiteralOneOf #137
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
Conversation
Enable literal type inference without 'as const' assertion by using TypeScript 5.0+ const type parameters. This maintains full backward compatibility while improving developer experience.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #137 +/- ##
=======================================
Coverage 99.88% 99.88%
=======================================
Files 54 54
Lines 903 903
Branches 120 120
=======================================
Hits 902 902
Misses 1 1 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR enhances the type system for isLiteralOneOf by adding a const type parameter, enabling automatic literal type inference without requiring as const assertions. This improves developer ergonomics while maintaining full backward compatibility.
Key changes:
- Updated
isLiteralOneOffunction signature to useconst T extends readonly Primitive[]for automatic literal type inference - Added comprehensive test coverage for the new functionality without
as constassertion - Included an unrelated lint configuration change
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| is/literal_one_of.ts | Added const type parameter to function signature and updated documentation example to demonstrate the simplified usage |
| is/literal_one_of_test.ts | Added new test case verifying literal type inference works correctly without as const assertion |
| deno.jsonc | Added lint rule exclusion for no-import-prefix (appears unrelated to the main feature) |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| "exclude": ["no-import-prefix"] | ||
| } | ||
| }, |
Copilot
AI
Nov 28, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This lint configuration change appears unrelated to the PR's main purpose of adding a const type parameter to isLiteralOneOf. The entire codebase already uses relative imports (e.g., "../_funcutil.ts", "./literal_one_of.ts"), so if no-import-prefix was actually causing issues, it would affect many files.
Consider removing this unrelated change from the PR, or if it's needed, explain why in the PR description and potentially submit it as a separate change.
| "exclude": ["no-import-prefix"] | |
| } | |
| }, | |
| } | |
| }, | |
| }, |
Summary
consttype parameter toisLiteralOneOfto enable literal type inference withoutas constassertionno-import-prefixlint rule indeno.jsoncChanges
Type System Enhancement (
is/literal_one_of.ts)<T extends readonly Primitive[]>to<const T extends readonly Primitive[]>as constrequirementTest Coverage (
is/literal_one_of_test.ts)as constassertionLint Configuration (
deno.jsonc)no-import-prefixrule to allow relative path importsDeveloper Experience Improvement
Before:
After:
Backward Compatibility
✅ Existing code using
as constcontinues to work without changes✅ All existing tests pass
✅ Zero breaking changes
Test Plan
deno test is/literal_one_of_test.tsas constas const