What is TypeScript

Sharon Watkins
2 min readMay 11, 2021

TypeScript is a strict superset of ECMAScript 2015, which is itself a superset of ECMAScript 5, commonly referred to as JavaScript. TypeScript is an open-source language which builds on JavaScript by adding static type definitions. Types provide a way to describe the shape of an object, providing better documentation, and allowing TypeScript to validate that your code is working correctly. It offers classes, modules, and interfaces to help you build robust components. All valid JavaScript code is also TypeScript code. You might get type-checking errors, but that won’t stop you from running the resulting JavaScript. TypeScript can be used to develop JavaScript applications for both client-side and server-side execution (as with Node.js ).

TypeScript stands in an unusual relationship to JavaScript. TypeScript offers all of JavaScript’s features, and an additional layer on top of these: TypeScript’s type system. For example, JavaScript provides language primitives like string, number, and object, but it doesn’t check that you’ve consistently assigned these. TypeScript does. This means that your existing working JavaScript code is also TypeScript code. The main benefit of TypeScript is that it can highlight unexpected behavior in your code, lowering the chance of bugs.

A transpiler, or source-to-source compilers, are tools that read source code written in one programming language, and produce the equivalent code in another language that has a similar level of abstraction. A good examples of transpiler is the Typescript transpiler which converts Typescript code to JavaScript. Transpilers differ from compilers in that compilers also convert code from one language to another language, but with compilers, both languages are very different in abstraction level. e.g. .java to .class file compilation.

TypeScript knows the JavaScript language and will generate types for you in many cases. For example in creating a variable and assigning it to a particular value, TypeScript will use the value as its type. By understanding how JavaScript works, TypeScript can build a type-system that accepts JavaScript code but has types. This offers a type-system without needing to add extra characters to make types explicit in your code.

--

--