Why TypeScript?

Learn about types and their advantages.

TypeScript is a tightly coupled language, and it is the superset of JavaScript. It lets us use every piece of code that runs in plain JavaScript. TypeScript is less prone to errors because we must define variable types before using them.

Dynamically-typed languages

Dynamically-typed languages are those in which a variable’s type is checked during runtime. This contrasts with static-typed languages in which the variable’s type is checked during compile time. Dynamically-typed languages require less typing, and combining functions is easy because the language believes we know what we’re doing.

Advantages of typing

Typing offers several advantages. We’ll go through each, one by one.

Types are beginner friendly

Strong typing provides many advantages, which are more apparent when writing functional code while working in an agile team. What are those advantages? Well, types are beginner friendly, meaning they help less experienced colleagues and developers who are new to the team. The latter might know the language but might be unfamiliar with the domain and code. Types tell team members more about how the function can be used. Take a look at the following TypeScript function:

Press + to interact
function sayHello(value: string): string {
// some code
}

A single glance tells us many things. The return type is a string, so presumably, the function won’t say hello by printing to the console. Instead, it returns its greeting. We can also guess that it will be a personalized greeting because we have a string parameter with the generic name value. It might contain a name or a title. It probably won’t contain an ...