# Introduction to TypeScript

TypeScript is a strongly typed programming language that builds on JavaScript, giving you better tooling at any scale.

## Type System

TypeScript adds optional static typing and class-based object-oriented programming to the language. 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.

### Basic Types

TypeScript supports several basic types including `string`, `number`, `boolean`, `array`, and `tuple`. These types allow you to add type annotations to your variables and function parameters.

## Interfaces

Interfaces define the shape of an object in TypeScript. They are a powerful way to define contracts within your code as well as contracts with code outside of your project.

```typescript
interface User {
  name: string;
  age: number;
  email?: string;
}
```

An interface can define optional properties using the `?` operator. This is useful when some properties may or may not be present.

## Classes

TypeScript supports full class-based object-oriented programming with inheritance, interfaces, and access modifiers. Classes provide a clean and reusable way to create objects.

```typescript
class Animal {
  private name: string;
  
  constructor(name: string) {
    this.name = name;
  }
  
  public move(distance: number = 0): void {
    console.log(`${this.name} moved ${distance}m.`);
  }
}
```

Access modifiers (`public`, `private`, `protected`) control visibility of class members.

## Generics

Generics provide a way to make components work with any data type and not restrict to one data type. They allow users to consume these components and use their own types.

```typescript
function identity<T>(arg: T): T {
  return arg;
}
```

Generics are particularly useful for building reusable data structures and functions that work across multiple types.

## Enums

Enumerations allow you to define a set of named constants. TypeScript provides both numeric and string-based enums.

```typescript
enum Direction {
  Up = "UP",
  Down = "DOWN",
  Left = "LEFT",
  Right = "RIGHT",
}
```

String enums are more readable than numeric enums because they provide meaningful string values at runtime.
