DEV Community

Acid Coder
Acid Coder

Posted on • Edited on

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

Top comments (3)

Collapse
 
tylim888 profile image
Info Comment hidden by post author - thread only accessible via permalink
tylim

test

Collapse
 
tylim88 profile image
Info Comment hidden by post author - thread only accessible via permalink
Acid Coder

test

Collapse
 
tylim888 profile image
Info Comment hidden by post author - thread only accessible via permalink
tylim

test

Some comments have been hidden by the post's author - find out more