What is TypeScript?
TypeScript is a statically typed superset of JavaScript. It provides optional static typing, classes, and interfaces. It also enables a number of ES.Next features to be used, without requiring use of another transpiler (such as Babel).
If you are already familiar with ES6 (or beyond), then congrats!—you are already well on your way to understanding the TypeScript syntax. If not, we recommend familiarizing yourself with ES6 beforehand to get the most out of TypeScript.
The TypeScript type system
What is static typing?
A language is said to be statically typed if the type of a variable is known at compile time. Some examples include C#, Rust, TypeScript.
A language is said to be dynamically typed if the type of a variable is known only once its run-time value is known. Examples: Ruby, Python, JavaScript.
Types are optional
TypeScript's optional typing is one of its more powerful and unique features.
Other statically typed languages like C# or Java require you to specify the type of the variable when declaring it.
For example, to declare a string in C#, the string
type must be specified:
string name = "Bonjour";
In TypeScript, declaring the type is completely optional. So both are valid:
const name = "Bonjour";
or
const name: string = "Bonjour";
Takeaway: types are explicit or implicit. We'll dive deeper into TypeScript's ability to infer types later on.
Duck typing
One of TypeScript’s core principles is that type-checking focuses on the shape that values have. This is often called "duck typing" or "structural subtyping".
We'll look more closely at how TypeScript uses duck typing in the section on Interfaces.
ES.Next
While the main focus of this guide is to cover TypeScript's unique features, TypeScript also provides a number of features that are planned in ES6 and beyond. The TypeScript team is actively adding these features, and the list continues to grow.
Last updated