'typescript inferred never is not never?
statement 1
type c = never extends never ? true : false // true
yup, as expected
statement 2
type d = never extends infer P ? P : false // never
P is never as expected
statement 3
type g = (never extends infer P ? P : false) extends never ? true : false // true
this makes sense, because we know from statement 2 P is never and from statement 1, never extends never is true, so it returns true
statement 4
type f = never extends infer P ? (P extends never ? true : false) : false // never, expecting true or at least false
this is totally unexpected, not only it did not returns true, it also did not returns false, but it returns never which is not in the options
this is very confusing, WHY?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
