DEV Community

Discussion on: The "any" type in Typescript - simple and short explanation

Collapse
 
ievolved profile image
Shawn Bullock

I think any is a lot like the default JavaScript type. Can be anything, and become anything. I love TypeScript as much as anyone. But I'll say, to eliminate some of its complaining and still get more of what I want than what it wants, I have to decorate with any. Viva la any.

Collapse
 
arikaturika profile image
Arika O

I understand what you mean. There are, of course, situations when you know better what you want to do with the code. I personally prefer not to use it at all when I do not know a type, since it defeats the purpose of Typescript. At work I am using it together with Eslint so I can't really put it in my code at all :).

Collapse
 
juliang profile image
Julian Garamendy

Exactly. I think almost anything is better than any.

In the example above we could go from number[] to (number | string)[], instead of resorting to any[]. Or generics, depending on the case.