DEV Community

Acid Coder
Acid Coder

Posted on • Edited on

1

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
tylim
Comment hidden by post author
Collapse
 
tylim88 profile image
Acid Coder
Comment hidden by post author
Collapse
 
tylim888 profile image
tylim
Comment hidden by post author

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

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay