Variables and Type Annotations
Let's look at Typescript variable types and annotations in this lesson.
We'll cover the following...
More on TypeScript
TypeScript allows but does not require us to annotate our JavaScript code with information about the types of various pieces of data in the code. TypeScript uses this information as a constraint on the values that those pieces of data can contain. If we declare a variable to be a number
and then assign it the string value "3"
, the TypeScript compiler will not allow the code to be compiled.
If we don’t add any explicit type information, however, we don’t get the full benefit of using TypeScript. It will still catch some errors, such ...