The shell to your turtle .. Typescript

I was scrolling posts on a regular day, when my attention was caught by an image of a turtle. The turtle itself was representing javascript and its shell was Typescript. i immediately laughed it felt like the perfect way to describe their relationship and the turtle was simply a plus.

All kinds of turtles are amazing

The Turtle named JavaScript

JavaScript is arguably the most popular programming language to this day and it continues to grow. The primary reason why JavaScript has become so popular is because it has also become the default language of the web(Frontend). In layman's terms it is the only language all browsers understand. If you don’t k now javascript you're missing out.

It is the language supported by all browser. This condition enforced web developer to begin learning the fundamentals of JavaScript if they wanted to continue further as a developer. As the web development industry demand exploded as did the need for web developers who knew JavaScript.

JavaScript is not an old programming language likeC or C++. Developed by Brendan Eich in 1995 in just ten days for the Netscape browser it was intended to be a scripting language that added dynamic behavior to the web page. Surprisingly , JavaScript didn’t take off with a good start. It wasn’t meant to a general-purpose programming language until later on.

In 2009,Ryan Dahl created a backend software that used Google Chrome’s V8 JavaScript engine and it ran on JavaScript. A backend framework using JavaScript was exhilarating to many people, especially to those who had a preference of backend to frontend. Thus Node.js was born.

The shell to the turtle, TypeScript

A team at Microsoft wanted to do something similar to Dart but they took a different approach. Their intention was not to reinvent the language with new syntax, they just amended the JavaScript syntax. Not only that, but they also made this new syntax optional. Thus TypeScript is born

All JavaScript programs are now a valid TypeScript program. Due to this reason, TypeScript began is also referred to as the superset of JavaScript. So what is this new syntax and what are types?

Let’s imagine the program running on the browser, what do you think will happen. I’ll get straight to it ,JavaScript will not throw any errors . First the data type of x is a number, then string when the string ‘hello is assigned to it and then the boolean when true is assigned to it.All of this is noticeable with the console.log statements. It’s the same and true for y . All these types are determined at the runtime.What TypeScript does was to provide a compiler that can process this program and throws errors if it detects something odd with the program.

What TypeScript adopts is an Erased Type System that removes type annotations as well as any type related information from the compiled program. The type annotations are only there to provide type information of values to the TypeScript compiler during the compilation process. This means Typescript falls under the category of statically typed languages.

TypeScripts goal is to catch mistakes in a program before it goes to production. Doing so will prevent problems at the runtime. Its goal is not to provide tools to amend or modify the original source code, basically it’s a safety net and it’s in high demand in all forms of big companies.

Being the superset of JavaScript, it has a responsibility to support existing standards of JavaScript But a developer can mistakenly use a feature from a standard that is pretty new such as Promise from ES6 and run the compiled program in an environment that doesn’t support Promises. Meaning it will not run at an optimal performance since it may not support it completely.

Fortunately there is a solution, this can be solved by TypeScript using a configuration file, mainly named tsconfig.json, that contains information about the project and what is expected from the TypeScript compiler. This is a plain JSON file.

Since the focus is shifted in this case is set to ES5, you would get a compilation error if you use any JavaScript feature that is not the part of ES5, such as Promise.It is safe to say that TypeScript will inform about most of the situations at the compile time that could possible cause issues at the runtime. It is the shell meant to help us write cleaner and better code.

More to the shell

The TypeScript compiler is written in JavaScript,I found this fact to be both funny and crazy. The very own safety net written in your own language. The original source code of this compiler is written in TypeScript, meaning Typescript was self hosted.

TypeScript is open-source and its official project repository is hosted on Github. The src directory contains the source code of the TypeScript compiler along with other programs.Within the lib directory you can find the type definitions for JavaScript APIs and browser APIs that are used by the TypeScript compiler to validate your code.

TypeScript has one of the best online documentation. You can easily spend more time reading this documentation from typescriptlang.org. TypeScript provides an online REPL to compile and test TypeScript programs online. They are extremely helpful and intend to only aid you.

The Shell that grows with you

TypeScript is here to stay. I had only ever previously heard of typescript from a fellow colleague in my cohort. It was extremely early when he shared about it but i remember being taken back by it and noting down how i had to look more into it. Unfortunately i became swamped with work and continued to procrastinate it.

Ive been in constant calls with many employees from different big companies, Nike, Lyft, Uber, Spotify you name it. Ive always been curious as to what languages can help us standout and grow as a developer, what languages the companies want to see in us developers. They have mentioned TypeScript every-time. It is something you may have to learn eventually so why not get your foot in the door already.

Full Stack Software Engineer || Entrepreneur at heart , engineer by training. Comedian in the eyes off my peers.