microsoft / microsoft/TypeScript
Inconsistent behaviour of `-?`
Open
Nobody has claimed this yet.
Bug
Domain: Mapped Types
Help Wanted
- Dominant language
- Go
- Stars
- 111k
- Forks
- 14.3k
- Avg merge
- 2d 4h
- Merged PRs (30d)
- 132
Description
🔎 Search Terms
optional mapped type
🕗 Version & Regression Information
- This changed between versions 5.4.5 and 5.5.4
⏯ Playground Link
💻 Code
type OptionalToUnionWithUndefined<T> = {
[K in keyof T]: T extends Record<K, T[K]>
? T[K]
: T[K] | undefined
}
type Intermediate = OptionalToUnionWithUndefined<{ a?: string }> // { a?: string | undefined }
type Literal = { a?: string | undefined } // same type as Intermediate
type Res1 = Required<Intermediate> // { a: string }
type Res2 = Required<Literal> // { a: string | undefined }
🙁 Actual behavior
Res1 and Res2 are different types
🙂 Expected behavior
they should be the same because the inputs are
Additional information about the issue
This issue may share the cause with #59902
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 linked TypeScript Playground reproduction using exactOptionalPropertyTypes and compare Res1 with Res2 across the reported 5.4.5 to 5.5.4 versions. Read the related issue #59902 for possible shared context; done means the two equivalent inputs produce the same Required result and the regression is covered.
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