Microsoft/TypeScript
Auf GitHub ansehenProblem with function types, <T>() => T extends X ? () : ()
Open
#56.721 geöffnet am 9. Dez. 2023
Cursed?Domain: check: Variance RelationshipsHelp WantedPossible Improvement
Repository-Metriken
- Stars
- (48.455 Stars)
- PR-Merge-Metriken
- (Durchschn. Merge 6T 17h) (9 gemergte PRs in 30 T)
Beschreibung
🔎 Search Terms
"function", "generic function"
🕗 Version & Regression Information
⏯ Playground Link
💻 Code
type Fn<X> = <T>() => T extends X ? 1 : 2
type Equals<X, Y> =
Fn<X> extends
Fn<Y> ? true : false
type A = Equals<{readonly a: 'A'}, {a: 'A'}>
🙁 Actual behavior
type A should shows true.
🙂 Expected behavior
type A should be false.
It works well when the code is like this.
type Fn1<X> = <T>() => T extends X ? 1 : 2
type Fn2<X> = <T>() => T extends X ? 1 : 2
type Equals<X, Y> =
Fn1<X> extends
Fn2<Y> ? true : false
type A = Equals<{readonly a: 'A'}, {a: 'A'}>
Additional information about the issue
No response