Transcript from the "Object Types & Interfaces" Lesson
>> Mike North: We've already touched on objects little bit. They're kind of, object types here, they look kind of like object values, except instead of key value, you have key type. I use Prettier to format my code, which is why I get the semi-colon here. I like this because looking at this, the fact that there's a semi-colon, it's one more thing that helps me understand, this is not a value, this is just a type.
>> Mike North: By default, all properties are mandatory. So we get an error here saying, streetName is missing in type houseNumber. Well, I've got an example of the error done here, streetName is missing in this but it's required in type that. And I want you to imagine this as TypeScript at that equal sign, trying to figure out a way to make the left hand side and the right hand side agree in terms of, are these types compatible?
[00:00:56] On the right hand side, we just have houseNumber, on the left, streetName, so that's why you're seeing the error message represented in this way. If you really wanted to make something optional, and this is not a bad thing, I typically use this if I have a function that takes a big options bag, big options object.
[00:01:15] Just use the question mark. Question mark like it may be there, it may not be there. And you see here we don't run into that problem. We could totally add it.
>> Mike North: I need a comma. streetName, there it is.
>> Mike North: So it's just streetName is empty string, it's a pretty exclusive address.
[00:01:34] But if I wanted to have another thing there that's not present on the type, I'd be busted for it. There is no x, why would you put it there, right?
>> Mike North: We'll go into interfaces in pretty deep detail. For now, I just want you to think of an interface as a name for one of these structures that we're creating, right?
[00:02:00] For now, you can think of it as only working with object types. There are other things we can do to make it work with things like functions. But all we are doing here is we are creating a name, address, that we can use anywhere that we were using a type before.
[00:02:15] And you can import and export interfaces from modules just like values.