Beginner's TypeScript Tutorial (18 exercises)
Problem

Inheriting Interface Properties

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

There are tests in place to ensure that all of the id values are the same.

Challenge

Your challenge is to do some refactoring to DRY out this code.

Consult the TypeScript docs to determine how you can share the id property without writing the same line of code repeatedly.

Transcript

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.

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.