Skip to content

Conversation

@lambdalisue
Copy link
Member

Summary

  • Add const type parameter to isLiteralOneOf to enable literal type inference without as const assertion
  • Maintain full backward compatibility with existing code
  • Exclude no-import-prefix lint rule in deno.jsonc

Changes

Type System Enhancement (is/literal_one_of.ts)

  • Changed type parameter from <T extends readonly Primitive[]> to <const T extends readonly Primitive[]>
  • Updated documentation example to remove as const requirement
  • Leverages TypeScript 5.0+ const type parameters for automatic literal type inference

Test Coverage (is/literal_one_of_test.ts)

  • Added test case verifying literal type inference works without as const assertion
  • Confirms both runtime behavior and type safety

Lint Configuration (deno.jsonc)

  • Excluded no-import-prefix rule to allow relative path imports

Developer Experience Improvement

Before:

const isMyType = is.LiteralOneOf(["hello", "world"] as const);

After:

const isMyType = is.LiteralOneOf(["hello", "world"]);

Backward Compatibility

✅ Existing code using as const continues to work without changes
✅ All existing tests pass
✅ Zero breaking changes

Test Plan

  • Run existing test suite: deno test is/literal_one_of_test.ts
  • Verify type inference without as const
  • Confirm backward compatibility with as const
  • Lint passes with updated configuration

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
Copy link

codecov bot commented Nov 28, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 99.88%. Comparing base (6ad122d) to head (e018f7d).
⚠️ Report is 2 commits behind head on main.

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.
📢 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.

Copy link

Copilot AI left a 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 isLiteralOneOf function signature to use const T extends readonly Primitive[] for automatic literal type inference
  • Added comprehensive test coverage for the new functionality without as const assertion
  • 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.

Comment on lines +9 to +11
"exclude": ["no-import-prefix"]
}
},
Copy link

Copilot AI Nov 28, 2025

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.

Suggested change
"exclude": ["no-import-prefix"]
}
},
}
},
},

Copilot uses AI. Check for mistakes.
@lambdalisue lambdalisue merged commit ee34ae0 into main Nov 28, 2025
11 checks passed
@lambdalisue lambdalisue deleted the feat/literal-one-of-const-type-param branch November 28, 2025 03:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants