Instructor: With that, we're almost done
with the core types.
There is one more type, which we already saw,
and that's the any type.
The any type is the most flexible type
you can assign in TypeScript.
This type doesn't tell TypeScript anything.
It basically means you can store any kind of value in there.
We got no specific type assignment.
TypeScript will basically never yell at you
when you use any.
Back in our code here,
if I would set the type of favorite activities to any,
would not get an error.
If it set it to any array, I at least tell TypeScript
that favorite activities is an array of something.
So if I would store just a single value I there,
I would get an error.
But as long as it is an array,
I can store whatever I want in there.
So any is really flexible.
And this can sound great at fist,
but actually it's a big disadvantage
and you absolutely want to avoid any whenever possible.
Because any takes away basically
all advantages TypeScript gives you.
It gives you the same experience
you have with vanilla JavaScript
where you also have to any type on everything so to say.
Any basically makes sure that the TypeScript compiler
can't check anything,
because if any property or any variable
can store any value,
well then there is not much to check, right?
So you can use any as a fallback
if you have some value, some kind of data
where you really can't know
which kind of data will be stored in there
and where you then maybe are using some runtime checks,
like we did here, at runtime to narrow down
what you want to do for certain values.
Then you could go with any.
But in other cases, you really wanna avoid any.
If you have a chance of knowing which kind of data
you're working with, be explicit about it.
Let TypeScript inference do its job
or explicitly set your own types.
Don't fall back to any if you don't need to.