Beginner's TypeScript Section 18 exercises
Problem

Inheriting Interface Properties

Here we have a User, Post, and Comment that all share an id property:


interface User {
id: string;
firstName: string;
lastName: string;
}
interface Post {
id: string;
title: string;
body: string;
}
interface Comment {
id: string;
comment: string;
}

There

Loading exercise

Transcript

0:00 In this exercise, we've got a bunch of duplicated interfaces where they all share this ID property. We've got User, Post, and Comment. We've got a bunch of tests down here to make sure that everything stays as it should be. If I remove title from here, then it's going to yell at me because this Post type is not equal to id:string; title:string; body:string.

0:25 Right from the off, this is like a refactor challenge. Your challenge is to make sure the tests continue to pass while getting rid of some of this duplication here. Ideally, we would find some way that User, Post, and Comment would inherit from an object which contained id:string. That's your challenge.