Hello there! π Welcome to my repository for Assignment 1: Advanced Problem Solving with TypeScript & OOP.
In this project, I've tackled 7 different coding problems to demonstrate my understanding of strict type safety, Object-Oriented Programming (OOP) concepts, and advanced TypeScript features like Generics and Type Guards. I've also written two technical blog posts to explain some core TypeScript concepts in a simple, easy-to-understand way.
Here is how I have organized the files for this assignment:
βββ solutions.ts
βββ blog-1.md
βββ blog-2.md
βββ README.md
I have implemented all the problem-solving tasks inside a single file (solutions.ts). I made sure to follow strict TypeScript rules, use proper naming conventions, and keep the code clean (no console.log statements left behind!).
Here is a quick overview of what I solved:
- Array Filtering: A function that strictly extracts even numbers from an array.
- String Reversal: A clean approach to reversing a given string.
- Union Types & Type Guards: A
checkTypefunction that safely identifies if a value is a"String"or"Number". - Generics & Constraints: A strongly-typed
getPropertyfunction that uses<T, K extends keyof T>to prevent invalid object keys. - Intersection Types: A
toggleReadStatusfunction that immutably updates aBookobject. - OOP & Inheritance: A base
Personclass and aStudentsubclass demonstrating inheritance and proper parameter properties. - Array Intersection: A logical function to extract common elements between two arrays.
Besides coding, I also wrote two blogs to share what I've learned:
-
Blog 1: Understanding Why
anyis a "Type Safety Hole" andunknownis your Best Friend- I discussed why using
anyis dangerous for a codebase and howunknown, combined with Type Narrowing, acts as a much safer alternative.
- I discussed why using
-
Blog 2: Generics in TypeScript: Reusable Code That Stays Strictly Typed
- I explained how Generics can save us from writing repetitive code while maintaining 100% type safety, with real-world examples.
You can easily run the solutions.ts file directly using Node.js. Whether you are on Windows using PowerShell or on Linux/Mac using Bash, the command is the exact same.
Open your terminal (PowerShell, Bash, or Command Prompt) and run:
node solutions.tsThanks for checking out my work! Developed with strict adherence to TypeScript and OOP best practices.