We have seen how type annotations are really valuable, but they involve a lot of extra typing. Luckily, TypeScript's powerful type inference system means we don't have to provide annotations all the time. We can use type inference when we immediately set a variable value.
Let's look at an example:
Let's add the following variable assignment in the TypeScript playground:
let flag = false;
If we hover our mouse over the flag variable, we can see that TypeScript has inferred the type as boolean:
If we add another line beneath this, to incorrectly set flag to Table, we get a type error:
So, when we declare a variable and immediately set its type, we can use type inference to save a few keystrokes.