No Implicit `any`
This lesson introduces the `noImplicitAny` compiler flag.
We'll cover the following
Definition
The first and the most important flag is noImplicitAny
. Let’s look at its definition from the documentation:
Raise error on expressions and declarations with an implied any type.
In other words, when you enable the flag, TypeScript will throw an error whenever it’s impossible to infer the type of something. Without the flag, TypeScript would automatically assume that the type is any
. With the flag enabled, you have to provide type annotation. You can still use any
, but now you have to do this explicitly.
noImplicitAny
in practice
Let’s look at the example of untyped function arguments. It’s not possible for TypeScript to infer their types unless you provide them with default values; so if you don’t type them explicitly, it will throw an error.
Get hands-on with 1400+ tech skills courses.