Skip to content

Conversation

Copilot
Copy link

@Copilot Copilot AI commented Oct 9, 2025

This PR adds comprehensive test coverage for the prior commit that changed rest spreading behavior to use Partial<T> instead of Omit<T, keyof T> when the omit key contains keyof T.

Background

The previous commit implemented a suggestion from microsoft#62572 to improve the type inference for rest spreading when using keyof T as the omitted key. Previously, the type system would produce Omit<T, keyof T>, but the more accurate type is Partial<T> since any property could potentially be omitted.

Test Coverage Added

This PR adds two complementary test files:

restSpreadingWithKeyofT.ts - Testing Partial behavior

Validates that Partial<T> is correctly used in 8 scenarios:

// Example: Using keyof T directly
function f1<T>(obj: T, key: keyof T) {
    const { [key]: removed, ...rest } = obj;
    return rest; // Type is Partial<T>
}

// Example: Union of keyof T parameters
function f2<T>(obj: T, k1: keyof T, k2: keyof T) {
    const { [k1]: _, [k2]: __, ...rest } = obj;
    return rest; // Type is Partial<T>
}

restSpreadingWithOmit.ts - Contrast cases

Shows when Omit<T, K> is still correctly used (6 test cases):

// Example: Specific literal key
function f1<T extends { a: string; b: number }>(obj: T) {
    const { a, ...rest } = obj;
    return rest; // Type is Omit<T, "a">
}

// Example: K extends keyof T (specific subset)
function f4<T, K extends keyof T>(obj: T, key: K) {
    const { [key]: removed, ...rest } = obj;
    return rest; // Type is Omit<T, K>, not Partial<T>
}

Validation

  • ✅ All new tests pass with expected baselines
  • ✅ Full test suite passes (98,897 tests)
  • ✅ Lint and format checks pass
  • ✅ Code review found no issues

These tests ensure the feature works correctly and provide clear documentation of the behavior for future maintainers.

Original prompt

Add testcases for the prior commit


💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.

Copilot AI and others added 2 commits October 9, 2025 19:48
Co-authored-by: RyanCavanaugh <6685088+RyanCavanaugh@users.noreply.github.com>
Co-authored-by: RyanCavanaugh <6685088+RyanCavanaugh@users.noreply.github.com>
@Copilot Copilot AI changed the title [WIP] Add test cases for the prior commit Add testcases for Partial<T> rest spreading with keyof T Oct 9, 2025
@Copilot Copilot AI requested a review from RyanCavanaugh October 9, 2025 20:05
Copilot finished work on behalf of RyanCavanaugh October 9, 2025 20:05
@RyanCavanaugh RyanCavanaugh marked this pull request as ready for review October 9, 2025 20:52
@RyanCavanaugh RyanCavanaugh merged commit 57242ff into fix62572 Oct 9, 2025
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