microsoft / microsoft/TypeScript
Can't assign to partial of intersection with mapped type over generic
Nobody has claimed this yet.
- Dominant language
- Go
- Stars
- 111k
- Forks
- 14.4k
- Avg merge
- 1d 19h
- Merged PRs (30d)
- 117
Description
🔎 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
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the minimal generic TypeScript example in the issue and reproduce the error using the current compiler. Investigate how the type checker handles Partial over an intersection containing a mapped type, and consider the issue done when the example accepts d: 1 while retaining the generic constraint.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100