DEV Community

loading...
Cover image for What is TypeScript Part one?

What is TypeScript Part one?

aweysahmed profile image Aweys Ahmed Updated on ・1 min read

If you have been learning JavaScript, chances are that you have heard of TypeScript.

TypeScript is a superset of JavaScript that is open-sourced and developed by Microsoft. It has to be compiled into vanilla JavaScript and it is less error prone.

It is intended to be scaled and used on large projects.

TypeScript is statically typed but that is an option. However, it is
recommended that you specify the type. JavaScript is dynamically
typed.

Here is an example of JavaScript's dynamic typing and TypeScripts optional Static typing. Below is an example of JavaScript

let goat = "Michael Jordan"
let retired = true
let championships = 6

The same variables would look like this in TypeScript

let goat: string = "Michael Jordan"
let retired: boolean = true
let championships: number = 6

In JavaScript, I could do this.

championships = "six"

However, this would not work in Typescript because we already assigned a data type to championship. The championship variable will only accept numbers.

This also can be used to set the return type for a function

const add = (num1: number, num2: number): number => {
  return num1 + num2;
}

By statically setting the type, we can reduce the potential for bugs in the future and this is a huge advantage over Javascript.

I have included a link from my github account for the TypeScript project from this course Learn TypeScript - 2020 Edition taught by Maximilian Schwarzmüller.

TypeScript project courtesy of Max's course from Udemy

Was able to build a web app using TypeScript using this course

I highly recommend the course if you are looking to learn TypeScript.

In part two of the blog post, I will cover the topic of Interfaces.

Discussion

pic
Editor guide