microsoft / microsoft/TypeScript
Destructuring all but one key dynamically via rest creates an unusable type by omitting all of its keys
Nessuno ha ancora preso questa issue.
- Lingua principale
- Go
- Stelle
- 111k
- Fork
- 14.3k
- Merge medio
- 2g 4h
- PR unite (30g)
- 132
Descrizione
### 🔎 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_
Guida per i contributori
Apri la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Direzione di ricerca
Inizia dalla riproduzione collegata in TypeScript Playground e traccia il modo in cui vengono verificati il destructuring di oggetti con chiavi calcolate e i tipi object-rest. Conferma la correzione verificando che `otherData` sia assegnabile a `Partial` nell’esempio generico, preservando al contempo il comportamento di omissione previsto.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- typescript
- Ambito
- compilers
- Tipo di issue
- Bug
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Stato di attività
- Ferma
- Chiarezza
- Abbastanza chiara
- Idoneità per principianti
- 35/100