You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

TypeScript疑似Bug:Omit与交叉类型组合导致属性丢失?

这是TypeScript的Bug吗?如何上报?

问题确认

这确实是TypeScript的类型系统Bug。当组合从接口可选成员提取的联合类型、Omit工具类型和交叉类型时,TypeScript的类型解析出现异常,导致原本应该存在的rendered属性被错误判定为不存在。

复现代码

interface Type1 {
    optionalA?: {
        rendered: string;
        text?: string;
    };
}
type MyType = Type1["optionalA"];

const x: MyType = { rendered: "on" };
const y: Omit<MyType, "text"> = { rendered: "on" };
const w: MyType & { text?: string } = { rendered: "on" };
// 此行报错:Object literal may only specify known properties, and 'rendered' does not exist in type ...
const z: Omit<MyType, "text"> & { text?: string } = { rendered: "on" };

报错详情

编译器抛出错误:

Object literal may only specify known properties, and 'rendered' does not exist in type 'Omit<{ rendered: string; text?: string | undefined; } | undefined, "text"> & { text?: string | undefined; }'

预期行为:代码无编译错误,rendered属性应被正确识别为合法属性。

上报步骤

  • 前往TypeScript官方GitHub的问题跟踪页面
  • 选择「Bug Report」模板创建新Issue
  • 填写必要信息:
    • 标题:清晰描述问题,例如「Omit与交叉类型组合处理可选成员提取的联合类型时丢失属性」
    • 复现代码:粘贴上述完整代码片段
    • 环境信息:标注你使用的TypeScript版本(如5.2.2)
    • 结果说明:明确指出代码应该无报错,但实际出现了属性不存在的错误

内容的提问来源于stack exchange,提问作者Jeff Zhong

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.02 18:52:40