#Weird type inference for parametric type alias
13 messages · Page 1 of 1 (latest)
Preview:```ts
type eq<T, U> = T extends U
? U extends T
? "true"
: "false"
: "false"
let foo: eq<false, boolean>
let bar: eq<true, boolean>
let baz: eq<true, false>
let bag: eq<false, false>
let far: eq<boolean, unknown>
let bat: eq<boolean, true>
let bam: eq<unknown, boolean>```
You can choose specific lines to embed by selecting them before copying the link.
When you compare types with extends it breaks out unions and compares each one
so boolean is effectively a union of false and true
so you get
true extends true extends true | false extends true extend false
===
true | false
It's called distribution, sigh
Preview:```ts
type eq<T, U> = [T] extends [U]
? [U] extends [T]
? "true"
: "false"
: "false"
let foo: eq<boolean, true>```
You can choose specific lines to embed by selecting them before copying the link.