All language subtitles for 005 Working with Array & Object Types_en

af Afrikaans
ak Akan
sq Albanian
am Amharic
ar Arabic
hy Armenian
az Azerbaijani
eu Basque
be Belarusian
bem Bemba
bn Bengali
bh Bihari
bs Bosnian
br Breton
bg Bulgarian
km Cambodian
ca Catalan
ceb Cebuano
chr Cherokee
ny Chichewa
zh-CN Chinese (Simplified)
zh-TW Chinese (Traditional)
co Corsican
hr Croatian
cs Czech
da Danish
nl Dutch
en English
eo Esperanto
et Estonian
ee Ewe
fo Faroese
tl Filipino
fi Finnish
fr French
fy Frisian
gaa Ga
gl Galician
ka Georgian
de German
el Greek
gn Guarani
gu Gujarati
ht Haitian Creole
ha Hausa
haw Hawaiian
iw Hebrew
hi Hindi
hmn Hmong
hu Hungarian
is Icelandic
ig Igbo
id Indonesian
ia Interlingua
ga Irish
it Italian
ja Japanese
jw Javanese
kn Kannada
kk Kazakh
rw Kinyarwanda
rn Kirundi
kg Kongo
ko Korean
kri Krio (Sierra Leone)
ku Kurdish
ckb Kurdish (Soranรฎ)
ky Kyrgyz
lo Laothian
la Latin
lv Latvian
ln Lingala
lt Lithuanian
loz Lozi
lg Luganda
ach Luo
lb Luxembourgish
mk Macedonian
mg Malagasy
ms Malay
ml Malayalam
mt Maltese
mi Maori
mr Marathi
mfe Mauritian Creole
mo Moldavian
mn Mongolian
my Myanmar (Burmese)
sr-ME Montenegrin
ne Nepali
pcm Nigerian Pidgin
nso Northern Sotho
no Norwegian
nn Norwegian (Nynorsk)
oc Occitan
or Oriya
om Oromo
ps Pashto
pl Polish
pt-BR Portuguese (Brazil)
pt Portuguese (Portugal)
pa Punjabi
qu Quechua
ro Romanian
rm Romansh
nyn Runyakitara
ru Russian
sm Samoan
gd Scots Gaelic
sr Serbian
sh Serbo-Croatian
st Sesotho
tn Setswana
crs Seychellois Creole
sn Shona
sd Sindhi
si Sinhalese
sk Slovak
sl Slovenian
so Somali
es Spanish
es-419 Spanish (Latin American)
su Sundanese
sw Swahili
sv Swedish
tg Tajik
ta Tamil
tt Tatar
te Telugu
th Thai
ti Tigrinya
to Tonga
lua Tshiluba
tum Tumbuka
tr Turkish
tk Turkmen
tw Twi
ug Uighur
uk Ukrainian
ur Urdu
uz Uzbek
vi Vietnamese
cy Welsh
wo Wolof
xh Xhosa
yi Yiddish
yo Yoruba
zu Zulu

Original subtitles

Now let's talk about the more complex types.

So arrays and objects here.

And let's start with arrays.

If I have my hobbies, that might be an array of strings.

Hence this type assignment is wrong.

This allows me to store a single string and hobbies

but I want to have an array of strings.

To tell Typescript that I want an array of strings in there,

we can instead assign this type string

with square brackets thereafter.

This tells TypeScript

that we want to have an array of strings in hobbies.

And of course we could have to same with an array of numbers

and array of Booleans, whatever.

But here I want to have an array of strings

and that allows me to store

an array of strings in there, like this.

Now this is possible.

If I would add a number, in addition to the strings,

I again would get an error

because that's not a string

and I'm making it very clear

that only an array of strings may be stored in hobbies.

So that's how we can set up array types.

Now we also can set types for entire objects.

Let's say I have a person variable,

and in there I don't wanna store a name or an age

but an object.

I want to be able to store something like this.

An object with a name and an age.

Something like that.

That should be stored in person.

Now, of course, this works like that

because TypeScript out of the box

without configuration is quite forgiving.

And it by default allows me to store any value

in a variable.

It has a special any type for this,

which we can see if we have our person.

The default type assumed is the any type

which we can all say explicitly set like this.

Which simply tells TypeScript,

I don't wanna tell you anything

about the types of values stored in this variable.

Anything is allowed.

And that of course is a fallback type,

which you typically should not use

because that kind of defeats the entire purpose

of using TypeScript in the first place.

With the any type,

you are basically back to standard Javascript.

So it's the default

but of course it's not what I wanna keep here.

Instead I wanna make it very clear

which kind of object can be stored in person.

I wanna allow this object for example

but storing another object with a different structure.

Where I have let's say just a Boolean in there.

That's something I don't wanna allow.

And for this, we can again add a type assignment

but now we wanna add an object type.

A type defining an object.

And for this, we then add curly-braces

just as we do it when we create an object.

But please note that this is not

on the right side of an equal sign here.

So we're not creating our object here.

Instead here, it's in the place where we set a type

for a variable on the right side of this colon

after the variable name.

And thefore this here is actually a type assignment.

And hence here, we're not creating an object

but instead we're using a TypeScript feature here

which is the object type definition.

So we're defining the type for an object.

We're defining the structure of an object.

And here we can then for example, say that person

should store objects that have a name field,

where the value of that name field is a string

and which have a age field where the value is number.

So where the value is of type number, I should say.

And with that, we're telling TypeScript that only objects

that have this kind of type should be storable

in that variable.

That's why I can store this object here

because that object down there has exactly the structure

I'm defining here.

It has a name field, which has a string as a value

and a age field, which has a number as a value

On the otherhand,

this object down here is not storable.

And hence, I'm getting an error here

because it is having the wrong type.

This objects type would be

that it has an isEmployee field,

which stores a value of type Boolean.

Which does not match this type description here.

So, comment this out.

And that's how we can define array types and object types.

Of course, we could also combine these two.

If I wanted to have an array full of people.

So full off people that have this type signature here,

then I could set the type of people here

to this object type.

So I'm repeating this

but as an array by adding square brackets thereafter.

Now I'm saying in people,

I don't wanna store a single object of that structure,

but an array of such objects.

And that's how we can then already get a bit more advanced

by combining different TypeScript features

and by combining different types.

Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.