microsoft / microsoft/TypeScript
Partial of a mapped type from a union of enums fails when these enums have common members
Nobody has claimed this yet.
- Dominant language
- Go
- Stars
- 111k
- Forks
- 14.3k
- Avg merge
- 2d 4h
- Merged PRs (30d)
- 132
Description
TypeScript Version: 4.0.5, 4.1.2, 4.2.0-dev.20201126
Works fine with TS 3.X
Search Terms: mapped type enum partial
Code
enum EnumA {
A = 'A',
B = 'B',
}
// A second enum with at least one key also in EnumA
enum EnumB {
B = 'B',
C = 'C',
}
type Mapped = {
[k in EnumA|EnumB]: string;
};
const partial: Partial<Mapped> = {
[EnumA.B]: 'value',
};
Expected behavior:
Should compile
Actual behavior:
Typescript complains that EnumA.B does not exist in Partial<Mapped> when declaring the partial variable:
Type '{ B: string; }' is not assignable to type 'Partial<Mapped>'.
Object literal may only specify known properties, and '[EnumA.B]' does not exist in type 'Partial<Mapped>'.
Related Issues: maybe https://github.com/microsoft/TypeScript/issues/37859 ?
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
Begin with the linked TypeScript Playground and the supplied enum, mapped-type, and Partial repro, then compare the reported behavior across the listed TypeScript versions. Done means the example compiles as expected when the mapped type is built from the union of enums, with regression coverage for the shared enum member case.
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