This assignment assesses your practical understanding of core TypeScript concepts from Modules 1, 2, and 3—including basic types, optional/default/rest parameters, readonly tuples, interfaces, type narrowing, generics, Promises, and Object-Oriented Programming (OOP).
All coding solutions must be implemented in a single file named solutions.ts.
Create a function multiplyValue that accepts a number value and an optional number multiplier.
- If
multiplieris provided, returnvaluemultiplied bymultiplier. - If
multiplieris not provided (undefined), returnvaluemultiplied by2by default.
- Handle
0properly when passed asmultiplier(multiplying by0must return0).
// Sample Input:
multiplyValue(10);
multiplyValue(10, 5);
multiplyValue(7, 0);
// Sample Output:
20
50
0Create a function processInput that accepts a value which may be a string, number, or boolean, and returns a formatted result based on the value's type:
- If the input is a string → trim any leading/trailing spaces and return it in lowercase.
- If the input is a number → return the number multiplied by 10.
- If the input is a boolean → return
"Active"iftrue, or"Inactive"iffalse.
- Write the correct union type for the function parameter and the return type.
- Use type narrowing (
typeof) to handle each case safely.
// Sample Input:
processInput(" TypeScript ");
processInput(7);
processInput(true);
processInput(false);
// Sample Output:
"typescript"
70
"Active"
"Inactive"Create a function formatCoordinate that accepts a readonly tuple representing a coordinate and location name in the exact order [latitude, longitude, locationName] ([number, number, string]), and returns a formatted location string.
- Apply the
readonlymodifier to the tuple parameter so it cannot be mutated inside the function. - Return the exact string format:
"Location: [locationName] ([latitude], [longitude])"without rounding the numbers.
// Sample Input:
formatCoordinate([23.81, 90.41, "Dhaka"]);
formatCoordinate([22.35, 91.78, "Chittagong"]);
// Sample Output:
"Location: Dhaka (23.81, 90.41)"
"Location: Chittagong (22.35, 91.78)"Create a generic function concatenateArrays that accepts multiple arrays of the same type T using rest parameters (...arrays: T[][]) and returns a single combined array containing all elements in the order they were passed.
- Must use a generic type parameter
<T>and rest parameters. - Do not use
any.
// Sample Input:
concatenateArrays(["a", "b"], ["c", "d"]);
concatenateArrays([1, 2], [3, 4], [5]);
// Sample Output:
["a", "b", "c", "d"]
[1, 2, 3, 4, 5]Define an interface Course with the following properties:
title(string)students(number)isPublished(boolean)
Then, create a function getPopularCourses that accepts an array of Course objects and a minStudents number. The function should return a new array containing only the courses where isPublished is true and students is greater than or equal to minStudents.
- Define the
Courseinterface with the exact property names and types. - Do not mutate the original array.
// Sample Input:
const courses = [
{ title: "TypeScript Mastery", students: 120, isPublished: true },
{ title: "Draft Course", students: 200, isPublished: false },
{ title: "Basic HTML", students: 45, isPublished: true },
{ title: "Next.js Pro", students: 85, isPublished: true }
];
getPopularCourses(courses, 80);
// Sample Output:
[
{ title: "TypeScript Mastery", students: 120, isPublished: true },
{ title: "Next.js Pro", students: 85, isPublished: true }
]Write a generic function pluckValues that accepts an array of objects (items: T[]) and a valid property key of those objects (key: K), and returns a new array (T[K][]) containing the values of that specific property from each object in the same order.
- Use generics with the
keyofconstraint (<T, K extends keyof T>). - Do not use
any.
// Sample Input:
const users = [
{ id: 1, name: "Rakib", role: "Admin" },
{ id: 2, name: "Sadia", role: "Editor" },
{ id: 3, name: "Tariq", role: "Subscriber" }
];
pluckValues(users, "name");
pluckValues(users, "id");
// Sample Output:
["Rakib", "Sadia", "Tariq"]
[1, 2, 3]Create an Employee class and a Manager subclass following these exact specifications:
-
Employeeclass:- Has a
protectedpropertyname(string) and aprivatepropertybaseSalary(number). - Constructor accepts
(name: string, baseSalary: number)in that exact order. - Has a method
getDetails()that returns"Employee: [name], Base Salary: [baseSalary]".
- Has a
-
Managerclass (extendsEmployee):- Adds a
privatepropertydepartment(string). - Constructor accepts
(name: string, baseSalary: number, department: string)in that exact order and callssuper(name, baseSalary). - Has a method
getRoleInfo()that returns"Manager of [department]: [name]".
- Adds a
- Use
protectedandprivateaccess modifiers as specified. - Return the exact string formats shown in the sample output.
// Sample Input:
const manager = new Manager("Alice", 50000, "Engineering");
manager.getDetails();
manager.getRoleInfo();
// Sample Output:
"Employee: Alice, Base Salary: 50000"
"Manager of Engineering: Alice"Create an async function validateAgeAsync that accepts a number age and returns a Promise<string>:
- If
ageis 18 or above, resolve after 1 second (1000ms) with the string"Access Granted". - If
ageis less than 18, reject immediately withnew Error("Access Denied: Must be 18 or older").
- Explicitly type the return value as
Promise<string>. - Use
new PromisewithsetTimeout(orasync/await) and reject using anErrorinstance (new Error(...)).
// Sample Input 1:
await validateAgeAsync(20);
// Sample Output 1 (resolves after 1 second):
"Access Granted"
// Sample Input 2:
await validateAgeAsync(15);
// Sample Output 2 (rejects with Error):
Error: Access Denied: Must be 18 or olderWrite two separate, technically detailed blog posts on any 2 of the following questions:
- What are the core differences between
typealiases andinterfacein TypeScript? When should you choose one over the other? - How does TypeScript's type hierarchy work with
any,unknown, andnever? Why isunknownalways preferred overany? - What is Type Narrowing in TypeScript? Provide practical examples using
typeof,instanceof, and theinoperator. - How do Generics work in TypeScript, and how do they help when working with asynchronous
Promise<T>responses? - Explain how Access Modifiers (
public,private,protected, andreadonly) work in TypeScript OOP with examples. - What happens to TypeScript code under the hood during compilation (
tsc), and what role doestsconfig.jsonplay? - Provide a practical example of combining Union (
|) and Intersection (&) types in TypeScript.
- File Naming: Submit each blog post in its own Markdown file named after the blog topic using the format
[blog-name].md(e.g.,type-vs-interface.md,type-narrowing.md). - Length Requirement: Every blog post must be between 150 to 300 words (or 15 to 25 meaningful sentences).
- Structure: Each blog must have a clear Title, Introduction, Detailed Body Paragraphs with Code Examples, and Conclusion.
- Language: English or Bangla.
All coding solutions must be placed in a single file named solutions.ts.
- Explicit Parameter & Return Types: You must explicitly write the parameter types and return types for every function and class method.
- Exact Function & Class Names: You must use the exact function, interface, and class names specified in the problem descriptions (
multiplyValue,processInput,formatCoordinate,concatenateArrays,Course,getPopularCourses,pluckValues,Employee,Manager,getDetails,getRoleInfo,validateAgeAsync). - Exact Output: Your function and method return values must exactly match the sample outputs, including spaces, punctuation, and capitalization.
- Correct:
"Employee: Alice, Base Salary: 50000" - Incorrect:
"employee: Alice, base salary: 50000"
- Correct:
- Clean Code: Use meaningful variable names and avoid using
any. - No Noise:
- Do not include comments like
// Problem 1,// Problem 2, etc., insolutions.ts. - Do not include any
console.logstatements or sample test calls in your finalsolutions.tsfile; alwaysreturnthe values from your functions/methods.
- Do not include comments like
- Originality: All code and blog writing must be your own work. Plagiarism (copying from friends, documentation, or AI generators) will result in a zero.
├── solutions.ts
├── [blog-name-1].md
├── [blog-name-2].md
└── README.md
- Repository Setup: Create a personal GitHub repository and push your completed
solutions.ts, two[blog-name].mdfiles, andREADME.md(inREADME.md, briefly include your assignment overview and links to your two blog files). - Visibility: Set the repository to Public.
- Submission: Paste the direct GitHub repository URL into the assignment submission box. Do not submit individual files or zip archives.
- Assignment Release (Module 4: Assignment-1): November 08, 2026 – 8:00 PM (Sunday)
- 60 Marks Deadline: November 09, 2026 – 11:59 PM (Monday)
- 50 Marks Deadline: November 10, 2026 – 11:59 PM (Tuesday)
- 30 Marks Deadline: November 10, 2026 (after 11:59 PM) to December 01, 2026 – before 11:59 PM (Next 21 Days)