2 ms·
Why is that last line a problem at all?
by BoorishBears 10y ago
Why is that last line a problem at all?
- k__ 10y agoIt implies that TS doesn't fully understand JS.
- BoorishBears 10y agoI wouldn't say that, that line is pretty much the main value proposition of the language though, is it really "not understanding JS" as much as extending it? If you really want it to understand Js you could just cast to Any, but to me it's huge that you can do what you do in that last line. Instead of guessing that Player has a mousePosition property, after casting you get told it has one, and get it's exact type.
- k__ 10y agoTo me it seemed the other way around. By casting, I'm telling the compiler that it has a mousePosition property. But I think you're right. This is an simple example and the Player object could have a huge bunch of properties I don't need to guess later, I just need to cast and be done with it.