Script Valley
TypeScript: Complete Course from Zero
Object Types and Interfaces/Assessment

Practice & Assessment

Test your understanding of Object Types and Interfaces

Multiple Choice Questions

5
1

Which feature is available in interface but NOT in type alias?

2

What does the & operator produce in TypeScript?

3

When does excess property checking apply?

4

What is the purpose of implements in a class declaration?

5

What type does Record<'admin' | 'user', boolean> produce?

Coding Challenges

1
1

Model a blog post system with interfaces

Create three interfaces: Author with id (number), name (string), and optional bio (string). Post with id (number), title (string), content (string), author (Author), tags (string array), and publishedAt (Date or null). PublishedPost that extends Post and requires publishedAt as Date (not null). Write a function isPublished(post: Post): post is PublishedPost that returns true if publishedAt is not null. Create two sample Post objects โ€” one published, one draft โ€” and use the type guard to log different messages. Estimated time: 20 minutes.

Medium

Mini Project

1

Library Catalog System

Build a typed library catalog module. Define interfaces for: Genre (a string union type: 'fiction' | 'non-fiction' | 'science' | 'history'), Book (id number, title string, author string, genre Genre, yearPublished number, available boolean), and Library (name string, books Book array, Record of genre to count called genreCounts). Implement four functions: addBook(library, book) returns updated Library, checkOut(library, bookId) returns updated Library or throws if not available, getByGenre(library, genre) returns Book array, and buildGenreCounts(library) returns the genre count Record. Compose everything into a working demo that adds five books and performs checkouts. Zero compile errors with strict mode.

Medium
Practice & Assessment โ€” Object Types and Interfaces โ€” TypeScript: Complete Course from Zero โ€” Script Valley โ€” Script Valley