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
- Project structure
- Features
- Requirements
- Quick start
- Scripts and commands
- How to use the examples
- Development notes
- Contributing
- License
- Contact
src/ts-assignment.ts- Example implementations for a series of TypeScript exercises (utilities, generics, classes, enums, async functions).dist/- Compiler output (configured viatsconfig.json).tsconfig.json- TypeScript compiler configuration (strict mode enabled).
- Demonstrates strict type-checking via
strict: trueintsconfig.json. - Generic utility functions with safe typing (e.g., concatenating arrays).
- Type narrowing examples using
typeofchecks 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.
- Node.js 12+ (for tooling and TypeScript CLI)
- npm (or yarn) for installing dev dependencies
- 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 - Type-check the project (no emit):
npx tsc --project tsconfig.json --noEmit- Build (emit to
dist):
npx tsc --project tsconfig.jsonBelow 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
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.
- TypeScript: project uses
strict: truefor production-like safety. - Split and test: for production, split
assignment.tsinto 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.
- This project is licensed under the terms of the MIT License.
- You may modify or replace it for client or proprietary work.
- Name: Md Abu Kayser - Full-Stack Engineer
- Project: typescript-interview-playbook
- Maintainer: md-abu-kayser
- GitHub: github.com/abu.kayser-official
- Email: abu.kayser.official@gmail.com
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!