- Now, hopefully, this code looks rather familiar
since we've talked about this before.
And the whole idea here is how you create an object,
which has dynamic keys that have a specific value.
For example, if you wanna group people by their name,
you would have a key for each name,
which in our case is a string.
And then you're going to have the actual person array itself
as the value.
This is very common, and you may see this code all the time
but there's actually multiple ways
you can create this exact same signature.
What we could do
if we wanted to create the same exact thing,
I'm just gonna copy this down so we can compare
and contrast them is I can use the built-in record type.
So this record type takes two generic types.
The first one is the type for your key,
which in our case is a string.
So whatever you have set here, that's what that type is.
And the second one is going
to take whatever your actual value is.
In our case, it is a person array.
Now, this has the exact same signature.
You can even see that it breaks down to the exact same code.
This record type is essentially just an alias
for doing this exact same thing.
And personally, I find the record type a little bit easier
to read than this index type up here.
So I generally lean more towards the record type
when I'm creating different signatures like this.
I like how it looks
and it's a really good way to create an object like this.
And what could I even do
if I wanted to be a little bit more specific,
I could say this is the person name property
'cause if I changed my name to a number or something,
this would still work just fine.
So this is a really great way to create objects
instead of using this index type.
Both of them do the exact same thing
so it doesn't matter which one you use.
I mean, you can see,
they boil down to the exact same code in TypeScript.
It's entirely a personal preference.
I just prefer this one
'cause I find it a little easier to read.