Microsoft/TypeScript

Can't assign to partial of intersection with mapped type over generic

Open

#56,905 创建于 2023年12月30日

在 GitHub 查看
 (2 评论) (0 反应) (0 负责人)TypeScript (6,726 fork)batch import
Domain: Mapped TypesHelp WantedPossible Improvement

仓库指标

Star
 (48,455 star)
PR 合并指标
 (平均合并 6天 17小时) (30 天内合并 9 个 PR)

描述

🔎 Search Terms

"mapped type", "mapped generic type", "intersection", "partial"

🕗 Version & Regression Information

Current version of Typescript, not sure if it's a regression

⏯ Playground Link

No response

💻 Code

Simple to reproduce:

type X = 'a' | 'b' | 'c'
const foo = <T extends X>() => {
    const result: Partial<{d:number} & {[P in T]: boolean}> = {
       // error: Type '{ d: number; }' is not assignable to type 'Partial<{ d: number; } & { [P in T]: boolean; }>'
        d: 1
    }
}

🙁 Actual behavior

I get an error

🙂 Expected behavior

I am able to use this type in general; I expect to be able to use a partial of it as well. The only thing I've found that satisfies the type is an empty object

Additional information about the issue

No response

贡献者指南