TypeScript and JavaScript

Photo by Austin Chan on Unsplash

TypeScript and JavaScript

The destiny between TypeScript and JavaScript

Table of contents

As a beginner in TypeScript, I loved everything about it, including its type-system and how VSCode supports it. I am a bit conservative, highly-aware, and security-conscious, and TypeScript naturally satisfies these preferences.

TypeScript is a strictly typed version of JavaScript. It doesn't provide the same freedom or the bugs that JavaScript often does.
I have been building with JavaScript for 2 years, but I have been curious and excited about using TypeScript.
Before sharing this article, I wanted to build a real-time messaging application with Node.js and JavaScript. Then I thought, why not use Node.js and TypeScript?

This thought also brought about a series of other thoughts:

Q1. Which one runs at last in the environment? TypeScript or JavaScript.

JavaScript runs last in the environment. TypeScript is a superset of JavaScript that gets transpiled (converted) into JavaScript before it is executed.

Q2. If we build with Typescript, do we push the TypeScript to the server (or production) environment?

Nope, typically you do not push the TypeScript files to the server. Instead, you transpile TypeScript into JavaScript and then push the resulting JavaScript files to the production environment. (TypeScript never leaves your development environment 👀).

Q3. If we push the transpiled JavaScript, surely we don’t have any need of the TypeScript?

Correct, once you have transpiled TypeScript into JavaScript and pushed the JavaScript to production, you generally do not need the TypeScript files in the production environment. However, you may still keep the TypeScript files in your source code repository for development purposes, as they provide type safety and other development-time features.

Typescript is transpiled into JavaScript, and it is the transpiled JavaScript that gets pushed and ultimately runs in the environment(whether that’s a browser or a Node.js server).

Summary:

Just for fun, you can use this media as a mnemonic tool to understand the irrevocable destiny between TypeScript and JavaScript.

TypeScript to JavaScript:

JavaScript to TypeScript: