microsoft / microsoft/TypeScript

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

Ouverte
#62,572 3 commentaires 0 réactions 0 personnes assignées Voir sur GitHub
Domain: Mapped Types Experimentation Needed Possible Improvement
Langage dominant
Go
Étoiles
111k
Forks
14.3k
Merge moyen
2 j 4 h
PR mergées (30 j)
132

Description

### 🔎 Search Terms

"Destructuring", "Omit, "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

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

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

Test({ 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_

Guide de contribution

Ouvrir le guide de contribution

Piste de recherche

Commencez par la reproduction liée dans TypeScript Playground et suivez la manière dont la déstructuration d’objet avec clé calculée et les types object-rest sont vérifiés. Confirmez la correction en vérifiant que `otherData` est assignable à `Partial` dans l’exemple générique, tout en conservant le comportement d’omission attendu.

Rédigé par le modèle d'indexation à partir du texte de l'issue.

Évaluation

Stack technique
typescript
Domaine
compilers
Type d'issue
Bug
Difficulté
4/5
Temps estimé
3-5 jours
Activité
À l'abandon
Clarté
Plutôt claire
Accessibilité débutants
35/100

Recevez les nouvelles issues par e-mail

Un résumé court des issues GitHub adaptées aux débutants.