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

Acid Coder @tylim88

About: Who needs meth when you have Typescript?

Joined:
Oct 31, 2021

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

Publish Date: Aug 22 '22
1 3
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

Comments 3 total

Add comment