-
Notifications
You must be signed in to change notification settings - Fork 13.2k
Open
Labels
BugA bug in TypeScriptA bug in TypeScriptDomain: Mapped TypesThe issue relates to mapped typesThe issue relates to mapped typesHelp WantedYou can do thisYou can do this
Milestone
Description
π Search Terms
keyof required keys key evaluation reduce getReducedType
π Version & Regression Information
- This is the behavior in every version I tried
β― Playground Link
π» Code
type distilled = distill<{
// ^?
foo: "default"
bar?: number
}>
// incorrectly inferred as unknown
type requiredDistilledKey = requiredKeyOf<distilled>
// ^?
// explicit declaration identical to hover of distilled
type declared = {
bar?: number
} & {
foo?: "default"
}
// now correctly inferred as never
type requiredDeclaredKey = requiredKeyOf<declared>
// ^?
type requiredKeyOf<o> = {
[k in keyof o]-?: o extends { [_ in k]-?: o[k] } ? k : never
}[keyof o]
type distill<t> = t extends object ? distillMappable<t> : t
type distillMappable<o> = {
[k in keyof o as k extends inferredDefaultKeyOf<o> ? never : k]: distill<o[k]>
} & {
[k in inferredDefaultKeyOf<o>]?: distill<o[k]>
}
type inferredDefaultKeyOf<o> = {
[k in keyof o]: o[k] extends "default" ? k : never
}[keyof o]
π Actual behavior
requiredDistilledKey inferred as unknown
π Expected behavior
requiredDistilledKey inferred as never, consistent with the equivalent declared version
Additional information about the issue
No response
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
BugA bug in TypeScriptA bug in TypeScriptDomain: Mapped TypesThe issue relates to mapped typesThe issue relates to mapped typesHelp WantedYou can do thisYou can do this