---
title: "TypeScript Guide 01: Introduction to TypeScript"
description: "A complete introduction to TypeScript, what it is, why it matters, and how to set up your first project with static typing"
author: "Angel Rada"
lang: en
url: https://radagva.dev/posts/typescript_guide_01_introduction
publishedAt: 2026-08-25T17:08:26.000Z
modifiedAt: 2026-09-02T13:31:01.000Z
tags: ["Typescript","Nodejs","Javascript","Backend","Frontend","Series"]
translations:
  es: https://radagva.dev/es/posts/typescript_guide_01_introduction.md
video: gQxYELcULuU
---

# TypeScript Guide 01: Introduction to TypeScript

## Video

Watch the full video on YouTube:

[![Introduction to TypeScript](https://i3.ytimg.com/vi/gQxYELcULuU/hqdefault.jpg)](https://www.youtube.com/watch?v=gQxYELcULuU&ref=radagva_blog)

## What is TypeScript?

TypeScript is a superset of JavaScript developed by Microsoft that adds static typing and improved syntax to the language. Unlike what many people think, TypeScript is not a completely new language with additional features, but rather a tool that enhances the existing development experience.

TypeScript was created by Microsoft in 2012 and since then has seen massive adoption in the development community. Today, most modern frameworks and libraries like Angular, React, and NestJS use TypeScript by default.

## Why is it Important?

JavaScript is a very permissive language that allows creating objects at runtime and accessing values that may or may not exist. While this flexibility is useful, it also creates uncertainty during development because we don't know for certain if an attribute or method actually exists.

TypeScript solves this problem with its static typing. For example, if we create an object with `firstName`, `lastName`, and `role` attributes, TypeScript will show us an error if we try to access an attribute that doesn't exist, like `name`.

## Installing Node.js

To start working with TypeScript we need to have Node.js installed. Visit [nodejs.org](https://nodejs.org/) and download the LTS (Long Term Support) version.

You can install Node.js in several ways:

- **nvm** (Node Version Manager): Recommended for managing multiple versions
- **fnm** (Fast Node Manager): A fast alternative to nvm
- **Direct installer**: Download the `.pkg` file for macOS or `.msi` for Windows

Once installed, verify the installation by running in your terminal:

```bash
node -v
npm -v
```

If you prefer to use **pnpm** as your package manager (recommended), you can also install it:

```bash
npm install -g pnpm
pnpm -v
```

## Creating Our First Project

Create a new folder for your project and navigate to it:

```bash
mkdir ts-example
cd ts-example
```

Initialize the project with your package manager:

```bash
pnpm init
```

This will create a basic `package.json` file.

## Installing Dependencies

Install TypeScript and the necessary dependencies:

```bash
pnpm add -D typescript @types/node tsx
```

- **typescript**: The TypeScript compiler
- **@types/node**: Type definitions for Node.js
- **tsx**: Tool for running TypeScript directly (optional but recommended)

Approve the esbuild installation when prompted:

```bash
pnpm approve-builds
```

## Configuring TypeScript

Initialize TypeScript configuration:

```bash
pnpm tsc --init
```

This will create a `tsconfig.json` file with all configuration options. The most important attributes are:

- **rootDir**: Defines where your project source files are located
- **outDir**: Defines where compiled files will be saved

## Project Structure

Create the basic structure of your project:

```
ts-example/
├── src/
│   └── main.ts
├── package.json
└── tsconfig.json
```

Create a `src/main.ts` file with basic code:

```typescript
console.log("Hello from TypeScript!")
```

## Scripts in package.json

Add scripts to your `package.json` to facilitate execution:

```json
{
  "scripts": {
    "dev": "tsx src/main.ts",
    "build": "tsc"
  }
}
```

Now you can run:

```bash
pnpm dev    # For development with watch mode
pnpm build  # To compile the project
```

## Running TypeScript

If you have Node.js 22.6 or higher, you can run TypeScript directly:

```bash
node src/main.ts
```

If you have an older version, use tsx:

```bash
pnpm dev
```

## Compiling the Project

To compile your project to JavaScript:

```bash
pnpm build
```

This will create a `dist/` folder with compiled files ready for production.

## Variables and Types in TypeScript

TypeScript allows us to define the type of our variables:

```typescript
// Type inference
let name = "Angel" // TypeScript infers it's a string

// Explicit typing
let age: number = 25
let isActive: boolean = true

// Union types
let identifier: string | null = "abc"
identifier = null // Allowed
```

## Static vs Dynamic Typing

In JavaScript you can reassign variables to any type:

```javascript
let name = "Angel"
name = 123 // No error
name = true // No error
name = {} // No error
```

In TypeScript, this generates an error if the type doesn't match:

```typescript
let name: string = "Angel"
name = 123 // Error: Type 'number' is not assignable to type 'string'
name = true // Error: Type 'boolean' is not assignable to type 'string'
```

## Primitive and Utility Types

TypeScript offers several primitive types:

- `string`: Text strings
- `number`: Numbers
- `boolean`: True/false values
- `null` and `undefined`: Null or undefined values
- `object`: Objects

It also offers utility types for arrays:

```typescript
// Array of strings
let names: string[] = ["Angel", "Maria"]
let names2: Array<string> = ["Angel", "Maria"]

// Objects with interfaces
interface User {
  firstName: string
  lastName: string
  role: string
}

let user: User = {
  firstName: "Angel",
  lastName: "Rada",
  role: "developer",
}
```

## Conclusion

TypeScript is a powerful tool that significantly enhances the development experience by adding static typing to JavaScript. While it doesn't add new runtime features, it provides security, better IntelliSense, and improved code maintainability.
