3 ms·
Absolutely. One of my strongest opinions about TS is that you should use it pragmatically. It's not worth burning hours of time trying to placate the TS compile
by acemarke 6y ago
Absolutely. One of my strongest opinions about TS is that you should use it pragmatically. It's not worth burning hours of time trying to placate the TS compiler if you know the code works okay - throwing in a `type $FixTypeLater = any` and moving on is an acceptable workaround depending on the situation:
https://blog.isquaredsoftware.com/2019/11/blogged-answers-learning-and-using-typescript/#lessons-opinions-and-takeaways https://blog.isquaredsoftware.com/2019/11/blogged-answers-le...
- nkingsy 6y ago“as unknown as MyType” usually works almost as well and avoids throwing you out into the cold untyped darkness. I also try not to let any escape function boundaries. Recast it to something better when returning something.
- eyelidlessness 6y ago> “as unknown as MyType” usually works almost as well and avoids throwing you out into the cold untyped darkness. No it doesn’t. You’re casting to `any` and hiding that fact. Both top types can be anything at all, `unknown` is only safer if you narrow it to something else by testing it. If you cast it to something else you’re just treating `unknown` as `any`.
- benrbray 6y agoOn the other hand, most of the time I'm willing to put in a little effort to express the desired types, since it dramatically improves the intellisense suggestions, making code edits / refactors much less of a mental burden. But yeah, sometimes you hit a wall and need to do something unsafe.
- lolive 6y agoIt all has to do with refactoring. And new people coming into the project. True fact: One day (or another), it happens.