microsoft / microsoft/TypeScript

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

オープン
#62,572 コメント 3 件 リアクション 0 件 担当者 0 名 GitHub で見る
Domain: Mapped Types Experimentation Needed Possible Improvement
主要言語
Go
スター
111k
フォーク
14.3k
平均マージ
2日 4時間
マージ済み PR(30日)
132

説明

### 🔎 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_

コントリビューションガイド

コントリビューションガイドを開く

調査の方向性

リンクされた TypeScript Playground の再現コードから始め、計算されたキーを持つオブジェクトの分割代入と object-rest 型がどのようにチェックされるかを追跡します。ジェネリックな例で `otherData` が `Partial` に代入可能であり、期待される省略の動作が維持されることを確認して、修正を検証します。

索引モデルが issue の本文から書いたものです。

評価

技術スタック
typescript
領域
compilers
issue の種類
バグ
難易度
4/5
見積もり時間
3〜5日
活発さ
停滞
明瞭さ
おおむね明確
初心者へのやさしさ
35/100

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。