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 个 reaction 已指派 0 人 在 GitHub 查看
Domain: Mapped Types Experimentation Needed Possible Improvement
主要语言
Go
星标
111k
派生
14.3k
平均合并
2 天 4 小时
30 天内合并 PR
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 复现开始,跟踪如何检查计算键对象解构和对象 rest 类型。通过检查在泛型示例中 `otherData` 可赋值给 `Partial`,同时保留预期的省略行为,确认修复有效。

由索引模型根据 Issue 内容生成。

评估

技术栈
typescript
领域
compilers
Issue 类型
缺陷
难度
4/5
预计耗时
3-5 天
活跃度
停滞
描述清晰度
基本清楚
新手友好度
35/100

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。