Skip to content

zahid-official/milestone-13-problemSolving

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

24 Commits
 
 
 
 
 
 
 
 

Repository files navigation

TypeScript Problem Solving

A hands-on TypeScript project demonstrating core language features through practical problem-solving - covering generics, type guards, union & intersection types, enums, OOP inheritance, async patterns and more.

GitHub Repo TypeScript Node.js ts-node-dev


🔍 Overview

This project is a focused TypeScript exercise project that tackles real-world coding problems using TypeScript's powerful type system. Each function demonstrates a specific language concept - from generics and type narrowing to class inheritance and async/await - making it an ideal reference for building type-safe, maintainable code.

Mastering TypeScript, one problem at a time.


✨ Problem Solving

No.ProblemFunction / ClassConceptDescription
1Format StringformatString()Optional ParametersConverts a string to uppercase by default, or lowercase when the optional toUpper flag is explicitly set to false
2Filter by RatingfilterByRating()Typed Object ArraysAccepts an array of objects with title and rating properties, returns only items with a rating greater than 4
3Concatenate ArraysconcatenateArrays<T>()GenericsMerges multiple arrays of any type into a single array using a generic type parameter <T> and rest parameters
4Vehicle & CarVehicleCarOOP & InheritanceBase Vehicle class with private members; Car extends it with an additional model property and getModel() method
5Process ValueprocessValue()Union Types & Type GuardsAccepts string | number, returns the string length for strings or doubles the value for numbers using typeof narrowing
6Most Expensive ProductgetMostExpensiveProduct()Interfaces & ReduceDefines a Product interface and finds the highest-priced product using .reduce(), returns null for empty arrays
7Day Type CheckergetDayType()EnumsUses a Day enum with all weekdays; returns "Weekend" for Saturday/Sunday and "Weekday" for the rest
8Async SquaresquareAsync()Async/Await & PromisesReturns a Promise<number> that resolves with the squared value after 1 second, or rejects for negative inputs

🛠️ Tech Stack

TechnologyVersionPurpose
TypeScriptES2024Statically typed language for JavaScript
Node.jsv18+JavaScript runtime environment
ts-node-dev-TypeScript execution with auto-restart on changes

🏗️ Architecture

┌──────────────────────────────────────────────────────────┐
│                    TypeScript Compiler                   │
│                   (tsconfig.json - ES2024)               │
├──────────────────────────────────────────────────────────┤
│                                                          │
│  src/index.ts                                            │
│  ┌────────────────────────────────────────────────────┐  │
│  │            Utility Functions                       │  │
│  │                                                    │  │
│  │  ┌──────────────┐  ┌───────────────────────────┐   │  │
│  │  │  formatString │  │  filterByRating          │   │  │
│  │  │  (Overloads)  │  │  (Array + Object Types)  │   │  │
│  │  └──────────────┘  └───────────────────────────┘   │  │
│  │                                                    │  │
│  │  ┌──────────────┐  ┌───────────────────────────┐   │  │
│  │  │ concatenate  │  │  processValue             │   │  │
│  │  │ Arrays<T>    │  │  (Union + Type Guards)    │   │  │
│  │  └──────────────┘  └───────────────────────────┘   │  │
│  │                                                    │  │
│  │  ┌──────────────────────────────────────────────┐  │  │
│  │  │  getMostExpensiveProduct (Interface + Reduce)│  │  │
│  │  └──────────────────────────────────────────────┘  │  │
│  ├────────────────────────────────────────────────────┤  │
│  │            OOP Hierarchy                           │  │
│  │  ┌──────────────┐                                  │  │
│  │  │   Vehicle    │◄── Base class (make, year)       │  │
│  │  │   └── Car    │◄── Derived class (+ model)       │  │
│  │  └──────────────┘                                  │  │
│  ├────────────────────────────────────────────────────┤  │
│  │            Enums & Async                           │  │
│  │  ┌──────────────┐  ┌───────────────────────────┐   │  │
│  │  │   Day Enum   │  │  squareAsync              │   │  │
│  │  │  (getDayType)│  │  (Promise + setTimeout)   │   │  │
│  │  └──────────────┘  └───────────────────────────┘   │  │
│  └────────────────────────────────────────────────────┘  │
│                            │                             │
│                            ▼                             │
│                   dist/ (Compiled JS)                    │
└──────────────────────────────────────────────────────────┘

📂 Project Structure

milestone-13/
│
├── package.json                   # Dependencies and scripts
├── tsconfig.json                  # TypeScript compiler configuration
│
├── src/
│   └── index.ts                   # All TypeScript problem solutions
│
└── dist/                          # Compiled JavaScript output

🚀 Getting Started

Prerequisites

RequirementDetails
Node.jsv18 or higher recommended
npmComes bundled with Node.js
TypeScriptInstalled as a dev dependency

Installation

# 1. Clone the repository
git clone https://github.com/zahid-official/milestone-13-problemSolving.git

# 2. Navigate to the project directory
cd milestone-13

# 3. Install dependencies
npm install

# 4. Start the development server
npm run dev

The application will compile and run via ts-node-dev with auto-restart enabled.


📜 Available Scripts

CommandDescription
npm run devRun TypeScript with ts-node-dev - auto-restarts on file changes
npm testRun the test suite (placeholder)

⚙️ How It Works

                      Source File (index.ts) ──► ts-node-dev watches for changes
                                                          │
                                          ┌───────────────┘
                                          ▼
                                TypeScript Compiler
                                (strict mode, ES2024)
                                          │
                              ┌──────────┴──────────┐
                              ▼                     ▼
                        Type Checking          Transpilation
                        (Catches errors        (Generates JS
                          at compile time)       in /dist)
                              │                     │
                              ▼                     ▼
                        Error Feedback ◄──    Node.js Runtime
                        (Developer fix)       (Executes output)
  1. Write - TypeScript functions are authored in src/index.ts with full type annotations.
  2. Compile - ts-node-dev transpiles TypeScript on-the-fly with --transpile-only for speed.
  3. Execute - The compiled JavaScript runs in the Node.js runtime environment.
  4. Watch - File changes trigger automatic re-compilation and re-execution via --respawn.
  5. Validate - TypeScript's strict mode catches type errors before runtime, ensuring code correctness.

🌟 Author

Zahid Official

Zahid Official

Web Developer | Tech Enthusiast

GitHub LinkedIn Email

Building type-safe solutions through clean code and continuous learning


🤝 Contributing

Contributions are welcome and appreciated! Here's how you can help improve this project:

# 1. Fork the repository

# 2. Create a feature branch
git checkout -b feature/your-feature-name

# 3. Make your changes and commit
git commit -m "feat: add your feature description"

# 4. Push to your fork
git push origin feature/your-feature-name

# 5. Open a Pull Request against the main branch

Mastering TypeScript, one problem at a time.

About

TypeScript problem-solving solutions exploring static typing, generics, type narrowing, OOP patterns, and asynchronous programming through practical hands-on exercises.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors