It's a good way to get started, and then incrementally type as much as you can, preferably everything.
Later on, or if you start a new project with TypeScript, it's a good idea to turn on noImplicitAny and only allow explicit any in very specific framework level code, unit tests or if you interface with an untyped framework.
this is terrible advise - you should be using unknown. using any you're basically disabling TS and will be under the false assumption that your code is ok while it's most likely missing a lot of runtime checks
Not true, in the absolute worst case, unknown is what you should be reaching for, but it's pretty rare that you can't create some kind of type to interface with JS if it's not already got types. You can even use jsdoc comments as type hints in the JS too if you own that code.
My not particularly hot hot-take: There's basically no legitimate use case for any apart from "I don't have time to type all this now, because I'm converting a massive project from JS to TS"
There are some cases where any must be used instead of unknown but they usually involve generic constraints and seem more like a bug than intended behavior
It's a good way to get started, and then incrementally type as much as you can, preferably everything.
Later on, or if you start a new project with TypeScript, it's a good idea to turn on
noImplicitAny
and only allow explicitany
in very specific framework level code, unit tests or if you interface with an untyped framework.The hassle really pays off later.
this is terrible advise - you should be using
unknown
. usingany
you're basically disabling TS and will be under the false assumption that your code is ok while it's most likely missing a lot of runtime checksBut if your code ever integrates with javascript you still need any everywhere so it's pretty pointless
Not true, in the absolute worst case,
unknown
is what you should be reaching for, but it's pretty rare that you can't create some kind of type to interface with JS if it's not already got types. You can even use jsdoc comments as type hints in the JS too if you own that code.My not particularly hot hot-take: There's basically no legitimate use case for
any
apart from "I don't have time to type all this now, because I'm converting a massive project from JS to TS"There are some cases where
any
must be used instead ofunknown
but they usually involve generic constraints and seem more like a bug than intended behaviorAh you're right there, and I also agree, that feels more like a bug than by design
Not necessarily, depending on your situation you can type the JS code yourself.
If the team making the JS code were using jsdoc then the Typescript compiler can recognize the comments and use it for type checking.
In some instances the compiler can infer types from JS code to do some basic validation.
Even if the external JS code is recognized as
any
, your own code that's using it still has types, so it's better than nothing.