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, because it calls getUserId
and passes in a defaultUser
that doesn't match the User
contract.
Challenge
Reference the TypeScript docs and determine how to change defaultUser
so that our test will pass.
Transcript
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.
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.
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.