Typescript WTF Moments 7: Boolean can extends Record<infer X,unknown>

tylim88

Acid Coder

Posted on August 22, 2022

Typescript WTF Moments 7: Boolean can extends Record<infer X,unknown>
type o = boolean extends Record<infer X, unknown> ? X : false // valueOf
//   ^?

console.log(true.valueOf()) // true
Enter fullscreen mode Exit fullscreen mode

playground

Boolean can extends Record because boolean in JS has properties "valueOf"

this may caught you off guard if you expect anything that extends Record is object type

💖 💪 🙅 🚩
tylim88
Acid Coder

Posted on August 22, 2022

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related