Microsoft/TypeScript
GitHub ã§èŠãConditional type eagerly calculated to be invariant breaks referential transparency
Open
#62,798 opened on 2025幎11æ23æ¥
BugCursed?Domain: check: Variance RelationshipsHelp Wanted
Repository metrics
- Stars
- Â (48,455 stars)
- PR merge metrics
-  (å¹³åããŒãž 6d 17h) (30d ã§ 9 merged PRs)
説æ
ð 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.)