So what is Typescript?
According to their website,
Okay, cool, but who really uses Typescript?
A lot of people do actually! Check out the 2019 survey from StackOverflow.
Typescript has also made the top 3 of the most loved languages in 2019 so we can see that many developers are finding immense value from this language.
Okay, okay, you got my attention. Now, tell me how Typescript can help me as a developer.
Show me some examples!
Here we are explicitly stating that this function “add” can only accept numbers as its parameters. When we try to pass in the string “hello” as the second argument, Typescript sees that this is an error, underlines the error in red, and gives us the error message below.
Typescript will give us an error message if we hover over the error underlined in red and when we try to transpile our code. The errors provided also give you a good indication on how the error can be fixed.
Another great thing about Typescript is that we don’t always have to specify types in our code because Typescript will automatically determine types if no specific type is explicitly stated, also known as “type inference.”
In this example, we are setting a variable “example” to the number “23”. When we try to reassign this variable to a string, Typescript has already assumed that this variable should only accept numbers as its value and will give you an error message. There are ways to go around this, especially if you wanted your variable to accept all types, but I won’t get into that here.
I hope this gives you a brief introduction to what Typescript is. I have only scratched the surface on what it can do to help us as developers.
Now, I want to try!
If you want to try playing with Typescript on your own, you can install it easily to your computer.
This installs it globally on your computer.
You must also make sure that your text editor is setup to support Typescript so you may need to install a plugin for Typescript in order to full take advantage of Typescript in your editor. If you are using Visual Studio Code, the support is built-in, so there’s nothing to install!
If you don’t want to install Typescript just yet, Typescript also has a page where you can try out the language without installing it on your computer.
For more information, you can also check out these links: