Skip to content

Destructuring all but one key dynamically via rest creates an unusable type by omitting all of its keys #62572

@branson-dyer

Description

@branson-dyer

🔎 Search Terms

"Destructuring", "Omit<Partial, "keyof type> not assignable to Partial",

🕗 Version & Regression Information

  • This is the behavior in every version I tried, and I reviewed the FAQ for entries about destructuring and Omit and found a somewhat related thing under 'Add a Key Constraint to Omit' but that isn't the change necessitated here

⏯ Playground Link

https://www.typescriptlang.org/play/?#code/JYOwLgpgTgZghgYwgAgJLmvJyDeAoZZABgC5kQBXAWwCNoBuA5AexAjIGcwpQBzRwmADuzMjWbMANhDghGAXzx4YFEAjDBWyACoQuAHgAmcMHG0BPAA4QAfAApjpso7NWIAGmSQuAaQjmyAGt-ZhhkFwtrAEpcJmkwZEs4KA04SQAREzgyAAVk1MkjLMjbZABecKyBZARWLhrJVggAdWAwAAtmCjA-c3LkO2CA5CHQytMSmLKbWMJCWpB6nGQAbSGAXTIAfU8AOn3mDuhM02R5fqSU4DSTuGrCS4Lb-sP246qAegAqL5LkAHIAPJUNr6PJXNJFCZuGyeUZhCIw-7IYAcciHZBwDgcYC8EBwGjSLzMLxuAHggpQ1zWGz-XZMP7-eHjakQZGo9EJLE4vEEolgElgMn-ACiAA8EJIKIYIPpmYjrHCQgjikj6XMdMKuDwQLxkAAfcjUOhQA3IDjmWhSdlokAY7m4-GElAC0nWAFsABu0DpTA1jO1fBtnMx2MdfJdguFXp9ux+HyY8mqkqarQ6XR6-js3kz5ii1SgEDAFCgIES+WuGSqeEUeF0BnQkFgiFsdmWpGQABYAEyeJpkABEHULEAHnmEomQ8EkHBQ8k8A6aA-zQA

💻 Code

interface Interface {
  0: number;
  one: string;
  two: boolean;
}

function Test<dataType>(data: dataType, testKey: keyof dataType) {
  let partialData: Partial<dataType> = data;
  const cloneWithoutKey = (key: keyof dataType) => {
    const { [key]: _, ...otherData } = partialData;
    partialData = otherData;/**Type 'Omit<Partial<dataType>, keyof dataType>' is not assignable to type 'Partial<dataType>'.
  Type 'keyof dataType' is not assignable to type 'Exclude<keyof dataType, keyof dataType>'.
    Type 'string | number | symbol' is not assignable to type 'never'.
      Type 'string' is not assignable to type 'never'.**/
  };
  cloneWithoutKey(testKey);
  return partialData;
}

Test<Interface>({ 0: 42, one: "three", two: false }, "one");

🙁 Actual behavior

otherData resolves to never and is not assignable to partial data

🙂 Expected behavior

the rest parameter should be resolved to a partial of the datatype

Additional information about the issue

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    Experimentation NeededSomeone needs to try this out to see what happensPossible ImprovementThe current behavior isn't wrong, but it's possible to see that it might be better in some cases

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions