-
Notifications
You must be signed in to change notification settings - Fork 13.1k
Open
Labels
BugA bug in TypeScriptA bug in TypeScriptCursed?It's likely this is extremely difficult to fix without making something else much, much worseIt's likely this is extremely difficult to fix without making something else much, much worseHelp WantedYou can do thisYou can do this
Milestone
Description
π Search Terms
Conditional types, Invariance, Referential transparency
π Version & Regression Information
Tried with v5.9.3
β― Playground Link
π» Code
type F<T> = { value: T extends object ? keyof T : T }
type R1 = F<{}> extends F<{ a: string }> ? "holds" : "does not hold"
// ^? "does not hold"
type Fa = F<{}>
type Fb = F<{ a: string }>
type R2 = Fa extends Fb ? "holds" : "does not hold"
// ^? "holds"π Actual behavior
R1 computes to "does not hold"
π Expected behavior
R1 computes to "holds"
Additional information about the issue
I'm assuming typescript eagerly calculates F to be invariant and then instead of checking the subtype relation on resolved types it calculates subtype relation of the parameters to F. (This would perhaps have made sense if F was explicitly annotated with in out T.)
Metadata
Metadata
Assignees
Labels
BugA bug in TypeScriptA bug in TypeScriptCursed?It's likely this is extremely difficult to fix without making something else much, much worseIt's likely this is extremely difficult to fix without making something else much, much worseHelp WantedYou can do thisYou can do this