-
Notifications
You must be signed in to change notification settings - Fork 510
feat(without, difference): Improve TypeScript type inference for without() and difference() #1509
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
base: main
Are you sure you want to change the base?
Conversation
…keeping backward compatibility
…g with backward compatibility
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
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 TypeScript type inference for the without and difference array utility functions by adding function overloads that leverage the Exclude<T, V> utility type to automatically narrow return types when literal values are provided.
Key Changes:
- Added function overloads with improved type inference using
Exclude<T, V>forwithoutanddifference - Updated JSDoc comments to document the new generic type parameters and narrowed return types
- Updated documentation across multiple languages (English, Korean, Japanese) to explain the enhanced type inference behavior
Reviewed Changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| src/array/without.ts | Added function overloads for type narrowing with Exclude<T, V> and updated JSDoc |
| src/array/difference.ts | Added function overloads for type narrowing with Exclude<T, V> and updated JSDoc |
| docs/reference/array/without.md | Updated documentation to describe enhanced type inference and added type annotations to examples |
| docs/reference/array/difference.md | Updated documentation to describe enhanced type inference and added type annotations to examples |
| docs/ko/reference/array/without.md | Updated Korean documentation with type inference details and fixed missing closing quote |
| docs/ko/reference/array/difference.md | Updated Korean documentation with type inference details |
| docs/ja/reference/array/without.md | Updated Japanese documentation with type inference details and fixed missing closing quote |
| docs/ja/reference/array/difference.md | Updated Japanese documentation with type inference details |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
I understand that this change might look somewhat excessive in terms of overloading — I made this update because I believe it’s an important improvement for achieving accurate type inference. The overload structure remains minimal (three concise layers) and fully backward-compatible, Thx |
Closed #1503
Description
This PR focuses on improving TypeScript type inference for the
withoutanddifferencefunctions.By adding smart overloads, the return type now narrows correctly when literal values are passed,
while preserving full backward compatibility for general use cases.
No runtime logic has been changed — this update only affects type declarations.
Changes
Introduced three overloads for both
without()anddifference():values: []→ returnsT[]values: V[]→ returnsExclude<T, V>[]values: T[]→ fallback for backward compatibilityEnsured
difference()andwithout()now share the same overload pattern and type behavior.Unified parameter style to
readonly T[]for consistency across array utility functions.Updated English (
without.mdx), Korean (without.ko.mdx), and Japanese (without.ja.mdx) documents to reflect:Exclude<T, V>[])const result = without(['a','b','c'] as const, 'a') → ('b' | 'c')[])Motivation
difference()withwithout()to ensure consistent behavior.Breaking Changes
None.
This change only improves type inference and does not modify runtime behavior or output.