This assignment comprises various problems that demonstrate fundamental TypeScript concepts, including data typing, interfaces for objects, class usage with inheritance, type checking, and manipulation of data structures. The solutions aim to showcase efficient and clear problem-solving techniques using TypeScript, adhering to best coding practices.
All coding solutions must be implemented in a single file named solutions.ts.
Create a TypeScript function filterEvenNumbers that accepts an array of numbers and returns a new array containing only the even numbers.
// Sample Input:
filterEvenNumbers([1, 2, 3, 4, 5, 6])
// Sample Output:
[2, 4, 6]Write a function reverseString that takes a string as input and returns the reversed version of that string.
// Sample Input:
reverseString("typescript");
// Sample Output:
"tpircsepyt";Define a union type StringOrNumber and create a function checkType that uses type guards to return "String" if the input is a string or "Number" if the input is a number.
// Sample Input 1:
checkType("Hello");
// Sample Output 1:
"String";
// Sample Input 2:
checkType(42);
// Sample Output 2:
"Number";Write a generic function getProperty that takes an object and a key, then returns the value of that key. Use constraints to ensure the key exists on the object.
// Sample Input:
const user = { id: 1, name: "John Doe", age: 21 };
getProperty(user, "name");
// Sample Output:
"John Doe";Define an interface Book with properties title, author, and publishedYear. Create a function toggleReadStatus that accepts a Book object and returns a new object with an added isRead property (boolean), defaulting to true.
// Sample Input:
const myBook = { title: "TypeScript Guide", author: "Jane Doe", publishedYear: 2024 };
toggleReadStatus(myBook);
// Sample Output:
{
title: "TypeScript Guide",
author: "Jane Doe",
publishedYear: 2024,
isRead: true
}Create a class Person with a name and age. Then, create a subclass Student that adds a grade property. Include a method getDetails in the Student class that returns a string with the student's name, age, and grade.
// Sample Input:
const student = new Student("Alice", 20, "A");
student.getDetails();
// Sample Output:
"Name: Alice, Age: 20, Grade: A";Create a function getIntersection that takes two arrays of numbers and returns a new array containing only the elements that are present in both arrays.
// Sample Input:
getIntersection([1, 2, 3, 4, 5], [3, 4, 5, 6, 7])
// Sample Output:
[3, 4, 5]Write an impactful and technically sound blog post covering two of the following topics. Your blog should be clear, concise, and include code examples where necessary to illustrate your points.
-
Why is
anylabeled a "type safety hole," and why isunknownthe safer choice for handling unpredictable data? Explain the concept of type narrowing. -
How do
PickandOmitutility types prevent code duplication while creating specialized "slices" of a master interface? Discuss how this keeps your code DRY (Don't Repeat Yourself). -
How do
Genericsallow you to build reusable components and functions that stay strictly typed regardless of the data structures passed in? -
How do the four pillars of OOPβInheritance, Polymorphism, Abstraction, and Encapsulationβhelp manage logic and reduce complexity in large-scale TypeScript projects?
All solutions must be placed in a single file named solutions.ts.
- Function Names: Use the exact names specified in the problem descriptions.
- Exact Output: Your return values must match the sample output exactly, including spaces, punctuation, and capitalization.
- Correct:
'Name: John Doe, Age: 30' - Incorrect:
'name: John Doe, age: 30'
- Correct:
- Clean Code: Use meaningful variable and class names.
- No Noise: * Do not include unnecessary comments.
- Do not include any
console.logstatements; return the values instead.
Submit each blog post in its own Markdown file:
- Format: Use a separate Markdown (
.md) file for each blog (e.g.,blog-1.md,blog-2.md). - Structure: Each post should have a clear Title, an Introduction, Body Paragraphs with code snippets, and a Conclusion.
- Language: English/Bangla.
- Clarity: Use proper Markdown headers and code blocks to make the post readable.
βββ solutions.ts
βββ blog-1.md
βββ blog-2.md
βββ README.md
- Repository Setup: Create a personal GitHub repository and push your completed files.
- Visibility: Set the repository to Public.
- Submission: Paste the direct repository URL into the assignment submission box. Do not submit individual files or archives.
- 60 marks: May 07, 2026, 11:59 PM
- 50 marks: May 08, 2026, 11:59 PM
- 30 marks: After May 08, 11.59 PM
The code & content must be your own. Avoid copy-pasting from documentation or `AI generators