After using TypeScript there's some features that I'm terrified of that seem counter intuitive. All the following examples produce NO errors and are with every single strict TS option enabled.
It's doing some checking though, I just don't understand the semantics. I would understand it's existence of TS had proper type casts, like in Flow, but I can't find anything like it.
-
-
It is a proper type cast. But it can ONLY narrow if that matched, or widen if that matches. Otherwise it will tell you to cast to unknown and then to x. Imo it's super convoluted to understand and could probably be better, but it's something I got used to.
-
So in your example: the type of an empty object literal is basically the same as the object (lowercased) type, and you can cast properties on it (which makes sense) but you can't cast it to an array. In the example it just is weird because clearly that literal doesn't have bar.
- 2 more replies
New conversation -
Loading seems to be taking a while.
Twitter may be over capacity or experiencing a momentary hiccup. Try again or visit Twitter Status for more information.
he/him 