DEV Community

Daniel M. Matongo
Daniel M. Matongo

Posted on

What is TypeScript

TypeScript, as its name suggests, is a typed superset of JavaScript, which means that all JavaScript code is valid in TypeScript – making it very easy to get started. In addition, TypeScript has several language features including static typing, most ES6 syntax, and object-oriented programming constructs. It is a compiled language, which means you’ll have to transpile it to JavaScript before it can be run.

TypeScript's main mission is simple: make JavaScript, which is a dynamically typed language, behave more like a statically typed language.

But whats the difference between dynamic and static typing?

Basics

Every feature provided in TypeScript is non-invading, meaning that it has syntax that doesn't overlap with any part of the JS code. This makes porting your JS app back and forth relatively easily.

You can specify your variable's type using the colon (:) followed by the actual name of the type:

const stringVar: string = "str";
Enter fullscreen mode Exit fullscreen mode

There are 6 basic, primitive types to remember:

number // represents any kind of numeric value
Enter fullscreen mode Exit fullscreen mode
string // represents any kind of string value;
Enter fullscreen mode Exit fullscreen mode
boolean // represents any boolean value, i.e. true or false;
Enter fullscreen mode Exit fullscreen mode
symbol // represents symbol values;
Enter fullscreen mode Exit fullscreen mode
null // represents null value only;
Enter fullscreen mode Exit fullscreen mode
undefined //represents undefined value only;
Enter fullscreen mode Exit fullscreen mode

What does TypeScript offer ?

  • Static Type Checking (Optional) – Like other high level programming languages like Java, C etc. TypeScript does provide static type checking unlike JavaScript. Although static typing requires some extra steps while writing code but it has its own advantages. With TypeScript, we can check and assign variables, parameters and function types. It is completely Optional and helps us find and prevent bugs. Also helps make code more readable and descriptive.
  • Class Based Objects – Another huge advantage is the use of Classes which provides the ability to use true object oriented programming in our applications and prevents use of prototype based objects. It also provides encapsulation, inheritance and modifiers.
  • Modularity – It helps make the code more modular.
  • ES6 Features – Support for ES6 features is also one of the main reasons for its popularity.
  • Syntax – TypeScript provides syntax which is closer to java and other high level languages (Syntactical Sugaring).

Latest comments (0)