Do you avoid using “any”?
  v1.0 Posted at 29/04/2016 5:41 AM by Tiago Araujo

TypeScript’s any keyword is a blessing and a curse.  It is a type that can be anything, where every possible property and method exists and also returns any. It can be casted to and from anything and is how you tell the compiler to get out of your way.

However, it’s easy to use it as a crutch, and as a result, miss out on handy intellisense, refactoring support and compile-time safety – the main benefits of TypeScript!

Aim to use any in the same way that you use the dynamic keyword in C# - that is, sparingly, and with careful consideration.

Figure: Bad example – I can pass anything into this method, so I get bad output at run time (“undefined undefined”)
Figure: Good example – using types means I get errors and intellisense support

Related rules

    Do you feel this rule needs an update?

    If you want to be notified when this rule is updated, please enter your email address: