-
Notifications
You must be signed in to change notification settings - Fork 13.1k
Open
Labels
BugA bug in TypeScriptA bug in TypeScriptDomain: Conditional TypesThe issue relates to conditional typesThe issue relates to conditional typesHelp WantedYou can do thisYou can do this
Milestone
Description
π Search Terms
"inference", "conditional type", "substitution type", "mapped type", "type constraint", "array", "union type"
π Version & Regression Information
This changed between versions 5.0.4 and 5.1.6
β― Playground Link
π» Code
type Renamed = readonly ({ [k: PropertyKey]: string } | undefined)[]
type Foo<T extends readonly (PropertyKey | undefined)[] | Renamed> =
T extends Renamed ? GetKeys<Required<T>> : Required<T>
// ~~~~~~~~~~
// Type 'Required<T>' does not satisfy the constraint 'Renamed'
type GetKeys<R extends Renamed> = { [K in keyof R]: keyof R[K] }
// usage
type A = Foo<['a'?]> // ["a"]
type B = Foo<[{ a?: 'b' }]> // ["a"]π Actual behavior
TS fails to see that Required<T extends Renamed> extends Renamed.
π Expected behavior
It should compile.
Additional information about the issue
Substitute readonly (PropertyKey | undefined)[] with something that is not an array and the problem disappears.
I get the same error when I do GetKeys<Id<T>> with type Id<T> = { [K in keyof T]: T[K] }.
Extract<Required<T>, Required<Renamed>> silences the error, but Extract<Required<T>, Renamed> does not.
Metadata
Metadata
Assignees
Labels
BugA bug in TypeScriptA bug in TypeScriptDomain: Conditional TypesThe issue relates to conditional typesThe issue relates to conditional typesHelp WantedYou can do thisYou can do this