There are times when you need to work with packages which aren't built with typescript in mind. For example, I'm working with two.js
package in a react + typescript project with strict mode turned on. I'm finding it very difficult to type each variable properly as I have no clue what a lot of functions return.
If I use any
or don't mention a type, I get annoying errors like variable implicitly has an 'any' type
and it feels like I'm in constant battle with the compiler instead of focusing on my work.
A lot of other languages have some function/keyword which gives you the exact class/type an object is based on. But in javascript's typeof
& instanceof
are completely useless as you can only use them to check if an object is of a certain class. And typeof
simply returns object
for any custom object.
I love typescript but this is very annoying. How do I get around this? I've tried googling online but couldn't find a solid way to deal with this problem.