Junior Javascript Developers Start Using Typescript Right Now

Patrick Kennedy
3 min readJul 18, 2020
Seriously though, I think it is 🧐

Real Quick Introduction

Wow, let's just start by acknowledging that Javascript is not going away anytime soon nor will people stop using it. Whether you are a fan or not it’s still important to understand Javascript as it is used in almost every codebase.

Now, I won’t pretend that Javascript does not have its flaws, most everything in this world has some sort of pros and cons list associated with it. One of the biggest problems that programmers of other languages have with Javascript is the fact that it’s not a typed language.

For those who don’t know what that means, essentially in languages like Java when you declare a variable that is going to hold on to a value, you must explicitly tell it what kind of data type it’s going to be. So if it's going to be a boolean you must tell it that it's going to be a boolean. Whereas in Javascript a variable can be any data type, whether it be a string, boolean, etc… This is convenient, but, it can be easily abused.

Why is not typing a problem?

  1. You get lost in the slew of data being returned and created, typing allows a developer to be more mindful and more confident when writing code. Simply because you have to know what kind of data you're working with.
  2. There are use cases that slip through the cracks, in the case of undefined variables, functions may not run when something is undefined. Typescript in specific will yell at you before it even compiles to fix this.
  3. Reduce the number of unit tests. Reducing unit tests is amazing, they can be very time consuming, and cutting out the data type to be tested saves so much time. The time you could be using to do other things.
  4. Ultimately typing makes you a more aware developer and can improve your workflow writing complex Javascript applications, especially if you are using a front end framework like React. Those two go together like cookies and milk. Even if you learning Javascript I would argue that typescript is a better way to learn Javascript.

Typescript Introduction

As you might have guessed typescript is simply slapping some types into Javascript. Typescript is a compiled language that just means the language compiles your typescript directly into machine-readable Javascript. This means it must be built every time you make a change to the code. Don't be afraid of typescript, it’s just normal javascript with types and is easy to implement and there are resources everywhere for it.

Read the docs. Read the docs. Read the docs. — In case you don't read docs already.

Please take a look at Typescript in 5 minutes on the typescript docs. It really does only take 5 minutes. After you have at least followed the install instructions let's take a look at a quick example of how this works in common places in Javascript code; Functions, variables, and objects (remember that arrays are just fancy objects).

Variables

Very simple, you say its a string, it’s gotta stay that. Note you can reassign a variable to another value of the same data type. Just in case that wasn’t clear.

Simple Typescript Variable Example

Functions

So you can start to see especially in functions how not typing can get messy in production or larger application. No user should have to see undefined in a string.

Objects

This is one of the few funky things in typescript. It prefers to not have concrete objects. You have to provide a template called and interface with types declarations for the keys inside of the object. This might seem tedious, but it ensures that the data you are putting into your object is of the correct type.

Conclusion

Thanks for reading, this is a very basic introduction to Typescript, and hopefully has swayed you to use it to continue your Javascript learning journey. Typescript can be even more useful in Front-End frameworks like to React. So, explore, and create amazing things.

--

--

Patrick Kennedy

Full Stack Software Engineer and Seeker of Knowledge