In this video, we're going to discuss why we care about tuples and when we might use them.
And I'll be honest with you, I am not a huge fan of tuples, and I don't think you're going to really
be using them in a very regular basis with TypeScript.
There are a couple of exceptions.
Most notably, I think that if you're ever working with a CSV file, any one represents, say, a single
row, you might reach out to a tuple will actually work at the CSV file later on inside this course.
And so you'll see a great example of that in action.
So let me tell you exactly why I don't think you're going to be using tuples that often at the bottom
of this file I'm going to declare a new variable called car specs like so and I'm going to assign it
some data that has a real important meaning around a car, like some specifications around a car.
So I'm going to assign it a tuple of four hundred three, three fifty for like.
So I'll make sure that I annotate the type on here to make sure it's really clear that this is a tuple.
So it's a number and a number like.
So OK, so here's the question.
What do these numbers mean to you?
I mean, looking at this line of code right here in isolation, what do those numbers mean?
Clearly, it has something to do with these specs around a car, but what is the purpose of these numbers?
Well, for us as engineers, I don't think that we can really look at this line of code and understand
what is going on here.
We know that there are two values.
We know that they are numbers, but that's pretty much it.
So let's try writing out that same type of data structure right here, but instead as an object, so
if I write out a very similar variable right here, maybe I'll call it car stats.
This time I'm going to make it an object.
And because it's an object, this time I have to add in a key and a value.
So for the value of 400, I'm going to give a key of horsepower.
Horsepower, there we go.
And then for the three three, five four, I'll put in weight like so.
All right, so what am I trying to illustrate here?
Well, if we use a tuple to represent some meaningful data, it's really hard for you and I as engineers
to look at this value right here and understand what we are trying to say.
However, in an object format right here, because we are forced to put in a key, it is immediately
obvious what we are working with.
I can look at this object right here and understand, oh, horsepower, 400.
Got it.
And then for weight, this is the weight of maybe a car in pounds three thousand three hundred fifty
four pounds.
So when we make use of an object to model a record, it's really clear what we were working with at
one glance.
But when we are working at the tuple, much harder to understand exactly what is going on at a glance.
So honestly, I think that in general, any time we want to model a record or record it in our application,
somehow we're going to stick with a JavaScript convention of reaching for an object as opposed to a
tuple.
Now, like I said, there are some corner cases where we might want to use this in some types of applications
and we will see an example of it later on inside.
Of course, actually, that's one of the first two or three applications we're going to work on.
All right, so I'm sorry to teach you about troubles and then say, hey, we're never going to use them,
but nonetheless, it is a feature of typescript that is very prominently kind of featured in the official
documentation.
So I just want to make sure you have at least a passing idea of what these type of things are all about.
So let's take a quick pause right here.
We're going to move on to our next topic in the next video.