TypeScript: An Introduction to the Superset of JavaScript

Kevin Goodman
2 min readApr 20, 2023

--

TypeScript is a programming language that is a superset of JavaScript, meaning that it understands the syntax and capabilities of JavaScript while adding additional features. The primary added value of TypeScript over JavaScript is static typing.

This means that type checking happens at code compile time. Type checking is a programming language’s way of verifying that all operations have received the correct data type to work with.

For example, a simple addition operation would expect at least two numbers. If one side of the addition operation is not a number, there may be type-checking errors or unexpected behavior. Microsoft developed TypeScript and released it to the public in 2012.

How does TypeScript work?

Browsers and most other platforms, like Node.js running JavaScript, do not have native support for TypeScript. TypeScript comes with a compiler called tsc that will take your beautifully crafted TypeScript files, strip out any extras, and convert them to JavaScript so that the browser (or whatever platform you’re using) can run your code as if JavaScript.

TypeScript VS JavaScript

JavaScript is a scripting language that helps you create interactive web pages, while TypeScript is a superset of JavaScript.

TypeScript is a powerful type system, including generic and JS features for large-sized projects, while JavaScript is an ideal option for small-sized projects. TypeScript code should be compiled, while JavaScript code should not be collected.

TypeScript supports the prototyping feature, while JavaScript does not support this feature.

TypeScript uses concepts like types and interfaces to describe the data used, while JavaScript has yet to learn.

Key Concepts of Typescript

Here are some key concepts for understanding Typescript:

Typescript Compiler: The TypeScript compiler is built into the installation, and the compiler transforms TypeScript code into JavaScript code.

tsconfig.json file: It is a configuration file used by the compiler to run under certain conditions. The tsconfig.json file in the directory indicates that the guide is the root of the TypeScript project.

Scripting Modules: As of ECMAScript 2015, JavaScript has the concept of modules. TypeScript shares this concept, using the same syntax for exporting and importing external modules.

Should I learn JavaScript or TypeScript?

TypeScript is on the 2022 list of top 5 programming languages developers love compared to JavaScript, which is in 16th place.

That said, no language is perfect, and TypeScript has some flaws. Developers familiar with JavaScript may initially feel it is much more restrictive and requires more boilerplate code.

TypeScript can also be challenging for more advanced use cases such as generics. However, don’t let that discourage you, so get a hand on it and see what you think!

--

--