TS Get Started

TypeScript Get Started

Getting started with TypeScript requires a Node.js environment installed.

You will use the Node Package Manager (NPM) to install the compiler globally.

Once installed, you can easily initialize and compile your code.

This step ensures your system is perfectly ready for development.


1. Installing TypeScript

To compile TypeScript, you need the official compiler called tsc.

You can install it globally on your computer so it's always available.

This allows you to write SEO-friendly code in any directory easily.

Install Command:

# Run this in your terminal
npm install -g typescript
# Verify installation
tsc -v

2. Initializing a Project

Every TypeScript project needs a configuration file for compiler options.

This file is called tsconfig.json and helps standardize your project.

Generating it is very simple and takes just a single command.

Initialize Command:

# Creates a new tsconfig.json file
tsc --init
# Now you are ready to code!

3. Compiling Your First File

Browsers cannot natively run TypeScript files (.ts) directly.

You must compile them into JavaScript (.js) before execution.

This compiled code is what gets parsed and indexed by search engines.

Compile Command:

# Compiles index.ts to index.js
tsc index.ts
# Run the resulting JS file
node index.js

Exercise

?

How do you globally install TypeScript using NPM?


4. Next Steps

Now that you have TypeScript installed, it is time to write code.

We will begin by exploring the most fundamental building blocks.

Let's move on to learning about the simple data types!