Beginner's TypeScript Section 18 exercises

Assigning Types to Variables

Here we have an interface that represents a user within our system:

interface User {
id: number;
firstName: string;
lastName: string;
isAdmin: boolean;

There's a function called getUserId that takes in a user, and returns its id.

Our test is currently failing, becaus

Loading exercise


0:02 We've got a tricky problem here. We're using an interface user as a way to represent the user within our system. We've got a function down here called getUserId, which takes in a user and returns its ID.

0:17 Now, this getUserId (defaultUser) is failing. It's failing because this defaultUser is not meeting this user contract. If I were to change it...I would say id, 1, firstName, Matt, lastName, Pocock, isAdmin, true, then it's going to pass.

0:43 I don't want the error to be down here. I ideally want the error to be at this line or around here, because I want to make sure that my defaultUser is matching that user contract. Your job is to go through the TypeScript docs and work out how you would do this.