Skip to content

A concise, strictly-typed TypeScript playbook with hands-on exercises demonstrating generics, interfaces, classes, union, intersection types and async patterns - ideal for interview prep and learning best practices.

License

Notifications You must be signed in to change notification settings

md-abu-kayser/typescript-interview-playbook

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

32 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

TypeScript Interview Playbook - Exercises and Patterns

A compact, well-typed TypeScript exercise repository demonstrating essential TypeScript features and idiomatic patterns for small utility functions and classes. This repo contains a collection of small functions and examples that showcase.

  • Strict typing and compiler configuration (see tsconfig.json)
  • Function overloading and generics
  • Type narrowing with union types
  • Interfaces and enums
  • Simple class inheritance and encapsulation
  • Asynchronous code with Promises

Table of contents

  • Project structure
  • Features
  • Requirements
  • Quick start
  • Scripts and commands
  • How to use the examples
  • Development notes
  • Contributing
  • License
  • Contact

Project structure

  • src/ts-assignment.ts - Example implementations for a series of TypeScript exercises (utilities, generics, classes, enums, async functions).
  • dist/ - Compiler output (configured via tsconfig.json).
  • tsconfig.json - TypeScript compiler configuration (strict mode enabled).

Features

  • Demonstrates strict type-checking via strict: true in tsconfig.json.
  • Generic utility functions with safe typing (e.g., concatenating arrays).
  • Type narrowing examples using typeof checks for union types.
  • Basic object/array manipulations (filtering by rating, selecting most expensive product).
  • Class inheritance with private members and method overrides.
  • Example of a Promise-based async function with proper error handling.

Requirements

  • Node.js 12+ (for tooling and TypeScript CLI)
  • npm (or yarn) for installing dev dependencies

Quick start

  1. Clone the repository and install dependencies:
git clone https://github.com/md-abu-kayser/typescript-interview-playbook.git 
cd typescript-interview-playbook 
npm install --no-audit --no-fund 
  1. Type-check the project (no emit):
npx tsc --project tsconfig.json --noEmit
  1. Build (emit to dist):
npx tsc --project tsconfig.json

Scripts and commands

Below are common commands you can use locally (you can add these to package.json scripts if desired):

  • Type-check only: npx tsc --project tsconfig.json --noEmit
  • Build: npx tsc --project tsconfig.json

How to use the examples

Open src/ts-assignment.ts to explore the provided examples. Each block demonstrates a focused concept - for example:

  • formatString(input: string, toUpper?: boolean): string - demonstrates optional parameters and normalization.
  • filterByRating(items) - shows array filtering with typed objects.
  • concatenateArrays(...arrays: T[][]): T[] - generic variadic function for safe concatenation.
  • Vehicle / Car classes - private fields, inheritance, and simple methods.
  • processValue(value: string | number): number - union type narrowing.
  • getMostExpensiveProduct(products: Product[]): Product | null - defensive programming with typed arrays.
  • enum Day and getDayType - enums and simple utility usage.
  • squareAsync(n: number): Promise - a Promise wrapper with explicit reject handling.

Development and tooling notes

  • TypeScript: project uses strict: true for production-like safety.
  • Split and test: for production, split assignment.ts into multiple modules and export functions for unit testing.
  • Formatting and linting: add Prettier and ESLint with TypeScript plugins to enforce style and catch issues early.

License

  • This project is licensed under the terms of the MIT License.
  • You may modify or replace it for client or proprietary work.

Contact and Maintainer


This project is ideal for interview homework, learning TypeScript fundamentals, or as a starter template to demonstrate TypeScript skills to clients.

Thank you for exploring this project!


About

A concise, strictly-typed TypeScript playbook with hands-on exercises demonstrating generics, interfaces, classes, union, intersection types and async patterns - ideal for interview prep and learning best practices.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published