Skip to content

Typescript general studies with mini-apps with the superset, tuples, generics, decorators, typed annotations, and typed arrays.

Notifications You must be signed in to change notification settings

dheysonalves/typescript-guide

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

28 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

TypeScript Learning Journey πŸš€

A comprehensive TypeScript study repository featuring practical examples, mini-applications, and advanced concepts. This project demonstrates the power of TypeScript's type system through hands-on implementations covering type annotations, generics, decorators, and modern design patterns.

πŸ“š Table of Contents

🎯 Overview

This repository serves as a practical guide to TypeScript development, showcasing real-world applications of type safety, object-oriented programming principles, and modern JavaScript features enhanced with TypeScript's powerful type system.

Key Features

  • Type Safety: Comprehensive examples of TypeScript's type system
  • Design Patterns: Implementation of common software design patterns
  • API Integration: Real-world examples with external APIs
  • Modern Tooling: Integration with modern development tools and bundlers

πŸ“ Project Structure

typescript-guide-1/
β”œβ”€β”€ lesson1/                 # HTTP requests with type safety
β”‚   └── fetchjson/          # Axios + TypeScript integration
β”œβ”€β”€ lesson2/                # Core TypeScript concepts
β”‚   β”œβ”€β”€ functions.ts        # Function type annotations
β”‚   β”œβ”€β”€ tuples.ts          # Tuple types and usage
β”‚   β”œβ”€β”€ typed-arrays.ts    # Array type definitions
β”‚   β”œβ”€β”€ types.ts           # Custom type definitions
β”‚   └── variables.ts       # Variable type annotations
β”œβ”€β”€ maps-project/          # Google Maps integration
β”‚   β”œβ”€β”€ src/
β”‚   β”‚   β”œβ”€β”€ User.ts        # User entity with location data
β”‚   β”‚   β”œβ”€β”€ Company.ts     # Company entity with faker data
β”‚   β”‚   β”œβ”€β”€ CustomMap.ts   # Custom map wrapper with type safety
β”‚   β”‚   └── index.ts       # Application entry point
β”‚   └── @types/            # Custom type definitions
└── sorting-project/       # Algorithm implementations
    └── src/
        └── index.ts       # Sorting algorithms with generics

πŸ“– Lessons

Lesson 1: HTTP Client with Type Safety

Focus: Leveraging TypeScript's type system for API interactions

Key Concepts Covered

  • Generic Type Parameters: Using axios.get<T>() for type-safe HTTP requests
  • Interface Definitions: Creating contracts for API response data
  • Type Assertions vs Generics: Comparing different approaches to type safety
  • Error Handling: Typed error handling in async operations

Technical Implementation

interface ITodoData {
    id: number;
    userId: number;
    title: string;
    completed: boolean;
}

const getTodoData = async (): Promise<void> => {
    const response = await axios.get<ITodoData>(url);
    const { id, title, completed } = response.data; // Fully typed!
}

Benefits Demonstrated:

  • Compile-time error detection
  • Enhanced IDE support with autocomplete
  • Self-documenting code through type definitions
  • Reduced runtime errors

Lesson 2: Core TypeScript Fundamentals

Focus: Mastering TypeScript's fundamental concepts and syntax

Variables & Type Annotations

  • Primitive Types: string, number, boolean, null, undefined
  • Type Inference: Letting TypeScript deduce types automatically
  • Type Assertions: Explicit type casting when necessary
  • Union Types: Combining multiple types with | operator

Functions

  • Parameter Annotations: Explicit typing of function parameters
  • Return Type Annotations: Specifying function return types
  • Contextual Typing: TypeScript's ability to infer types from context
  • Function Overloads: Multiple function signatures

Advanced Types

  • Tuples: Fixed-length arrays with specific types per position
type Coordinates = [number, number]; // [latitude, longitude]
type UserInfo = [string, number, boolean]; // [name, age, isActive]
  • Typed Arrays: Homogeneous collections with type safety
const userNames: string[] = ['Alice', 'Bob', 'Charlie'];
const mixedData: (string | number)[] = ['Alice', 25, 'Bob', 30];

🎯 Mini Applications

Google Maps Integration Project

Maps Application Screenshot

Technical Overview

A sophisticated mapping application demonstrating advanced TypeScript patterns and Google Maps API integration.

Architecture: Object-Oriented Design with TypeScript

Core Components

  1. CustomMap Class:

    • Implements the Facade pattern to simplify Google Maps API
    • Provides type-safe wrapper for map operations
    • Manages marker creation and positioning
  2. User & Company Entities:

    • Demonstrates class-based architecture
    • Integration with faker-br for realistic test data
    • Implements common interface for mappable objects
  3. Type Definitions:

    • Custom type declarations for faker-br library
    • Google Maps API type integration
    • Interface contracts for consistent object structure

Design Patterns Implemented

Facade Pattern:

class CustomMap {
    private googleMap: google.maps.Map;

    constructor(divId: string) {
        this.googleMap = new google.maps.Map(/* ... */);
    }

    addMarker(entity: Mappable): void {
        // Simplified interface hiding Google Maps complexity
    }
}

TypeScript Features Showcased

  • Interface Contracts: Ensuring consistent object shapes
  • Generic Constraints: Type-safe operations on different entity types
  • Utility Types: Leveraging built-in TypeScript utilities
  • Type Guards: Runtime type checking for enhanced safety
  • Declaration Files: Custom .d.ts files for third-party libraries

Technology Stack

  • TypeScript 4.5+: Latest language features
  • Google Maps JavaScript API: Interactive mapping
  • Parcel: Zero-configuration build tool
  • Faker-br: Brazilian locale data generation

Sorting Algorithms Project

Focus: Implementing generic algorithms with TypeScript

Features

  • Generic sorting implementations
  • Type-safe algorithm interfaces
  • Performance comparison utilities
  • Concurrent build and run setup with nodemon

πŸ›  Installation & Setup

Prerequisites

  • Node.js (v14 or higher)
  • npm or yarn package manager
  • Google Maps API key (for maps project)

Quick Start

# Clone the repository
git clone <repository-url>
cd typescript-guide-1

# Install dependencies for each project
cd lesson1/fetchjson && npm install
cd ../../maps-project && npm install
cd ../sorting-project && npm install

# Run individual projects
cd lesson1/fetchjson && npx ts-node index.ts
cd maps-project && npm run parcel
cd sorting-project && npm start

πŸ”§ Technologies Used

Technology Purpose Version
TypeScript Type-safe JavaScript 4.5+
Axios HTTP client library 0.24.0
Google Maps API Interactive mapping 3.47+
Parcel Build tool & bundler Latest
Faker-br Test data generation 0.4.1
Nodemon Development server 2.0+
Concurrently Parallel script execution 7.0+

πŸŽ“ Learning Outcomes

After exploring this repository, you will have gained practical experience with:

Core TypeScript Concepts

  • βœ… Type annotations and inference
  • βœ… Interfaces and type aliases
  • βœ… Generic programming
  • βœ… Union and intersection types
  • βœ… Utility types and mapped types

Advanced Patterns

  • βœ… Object-oriented programming with TypeScript
  • βœ… Design pattern implementation
  • βœ… API integration with type safety
  • βœ… Error handling strategies
  • βœ… Module system and declarations

Development Workflow

  • βœ… TypeScript compilation and tooling
  • βœ… Integration with popular libraries
  • βœ… Testing strategies for typed code
  • βœ… Build optimization techniques

Real-World Applications

  • βœ… Building type-safe web applications
  • βœ… Working with external APIs
  • βœ… Managing complex data structures
  • βœ… Performance optimization considerations

This project is designed for educational purposes and demonstrates best practices in modern TypeScript development.

About

Typescript general studies with mini-apps with the superset, tuples, generics, decorators, typed annotations, and typed arrays.

Topics

Resources

Stars

Watchers

Forks