Skip to content

When should I explicitly add the type annotations in Typescript? [closed]

it’s best not to add annotations when the type system would end up inferring the same type anyway.

Please give some examples for when to add the type annotation and when not to.
How do I know when Typescript will be able to determine the type on its own?



When TS cannot infer a type, it sets it to any. There’s an option noImplicitAny, which tells the compiler to warn you about such cases, so that you can see which types are not inferred and annotate them.