In this series of articles, we will introduce TypeScript, a popular programming language
We will cover the basics of TypeScript, including its syntax, data types, and type annotations, as well as some advanced features such as interfaces, classes, and decorators.
By the end of this track, you will have a good understanding of what TypeScript is and how it can help improve your development workflow!
Types in TypeScript
And that's exactly how the TypeScript Website describes it.
And going back to what we've just established – it achieves this through types.
JS is a dynamically typed language, meaning you can write
let testVar= 5, and JS will recognize it as an Integer.
let testVar = 5; testVar ="5";
let variable = 5; variable = "5";
As you can see, our variable was originally of type number, but now it has been assigned a value of type string.
What if you lose track of what data type our variable is?
Sounds benign but it's actually a huge problem, it's simply not very efficient to keep searching back in your code to see what data types our variables are!
That challenge becomes even more complex when the code was written by another developer.
Variables may be misused and accidentally changed without any word of warning from the interpreter. This can introduce bugs into the program because returning a string instead of a number could cause your program to malfunction.
Turning back our attention back to TypeScript now, once a variable is a particular type, it cannot be changed back.
Popular Reasons to Learn TypeScript
- Reduces Errors - Research has shown that TypeScript can help spot 15% of the most common bugs.
- Readability – It better documents the code as it's a lot more explicit, in simpler terms, It is easier to see what the code is supposed to do. This is especially useful when you're working in a team, and you need to understand what other developers intended to do with their code.
- It's Popular – knowing TypeScript will enable you to apply for some great jobs. Google, Facebook, Microsoft, and many more big names work with TypeScript. It's also the primary language employed in the Angular framework, one of React's main competitors. Some organizations are really starting to push for TypeScript for many of the reasons we will explore in this course.
We call that process compilation.
Compilation is an umbrella term for a process that takes code written in one language and converts it into code written in another language. It's like taking a recipe written in Spanish and translating it into English so that someone who speaks English can understand it.
The specific type of compilation TypeScript does is called Transpilation.
Transpilation is a type of compilation where the output of transpilation is typically readable by humans whereas the output of regular compilation is often highly optimized and difficult for humans to understand.
An example of standard compilation can be found Java which, like TypeScript, is a compiled language. Java source code is compiled down to bytecode. Bytecode is a compact and efficient representation of a Java program that is designed to be easy for a virtual machine (such as the Java Virtual Machine, or JVM) to interpret and execute. It is not a language that is meant to be read and understood by humans, but rather it is a representation of the program that is optimized for execution by a virtual machine.
In addition to TypeScript, another example of a language that is transpiled is Sass.
In the next step of this course, we'll take an actual look at TypeScript in action.