A perplexing part of TypeScript for me, which led me to write a bunch of unsafe code without realizing it: the `{}` type doesn& #39;t mean "an empty object". It means something more like "any value at all". It will take any object, but also strings, numbers, etc. Very dangerous.
I& #39;m sure that there& #39;s some weird backwards-compatibility reason for this design choice. This is the price that we pay for the sins of our forebears.
The specific way this bit me was: I defined a class that was generic over an object type. The base case of that class was supposed to have an empty object as its type parameter, so I instantiated it with {}. Oops; I effectively turned the type system off from that point forward.
You can follow @garybernhardt.
Tip: mention @twtextapp on a Twitter thread with the keyword “unroll” to get a link to it.

Latest Threads Unrolled: