Introduction to TypesScript

Get introduced to Typescript in this lesson.

Introducing TypeScript

In programming, the type variable data indicates the set of values that are valid for that data. For example, if a variable is an integer, we would expect the variable to have a value such as 1, -3, or 357 and not a value like banana. If the variable is set to a value that is not of the expected type, we think that something bad will happen. In some languages, attempting to set data to the wrong value leads to a compiler error, in other languages it leads to incorrect or unspecified behavior at runtime.

All high-level programming languages use some concept of type to determine behavior, which is to say that all these languages determine behavior by using not just the value of a variable in the system but also information about what kind of value it is.

TypeScript is a superset of JavaScript that allows us to optionally add annotations to the code to specify type information. TypeScript requires a compilation step that enforces type consistency and converts valid TypeScript to JavaScript that is suitable for browsers.

The type system that TypeScript uses makes inferences about types based on the code, even if we do not provide type information. The goal of TypeScript is to reduce code errors, first by preventing type mismatches, and as we become more advanced, by making invalid states into compile-time errors so they are impossible to achieve at run time.

Get hands-on with 1000+ tech skills courses.