What is TypeScript?
Last updated
Last updated
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 ).
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 beforehand to get the most out of TypeScript.
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.
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:
In TypeScript, declaring the type is completely optional. So both are valid:
or
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".
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.
Takeaway: types are explicit or implicit. We'll dive deeper into TypeScript's ability to later on.
We'll look more closely at how TypeScript uses duck typing in the section on .