Afrikaans
Akan
Albanian
Amharic
Arabic
Armenian
Azerbaijani
Basque
Belarusian
Bemba
Bengali
Bihari
Bosnian
Breton
Bulgarian
Cambodian
Catalan
Cebuano
Cherokee
Chichewa
Chinese (Simplified)
Chinese (Traditional)
Corsican
Croatian
Czech
Danish
Dutch
English
Esperanto
Estonian
Ewe
Faroese
Filipino
Finnish
French
Frisian
Ga
Galician
Georgian
German
Greek
Guarani
Gujarati
Haitian Creole
Hausa
Hawaiian
Hebrew
Hindi
Hmong
Hungarian
Icelandic
Igbo
Indonesian
Interlingua
Irish
Italian
Japanese
Javanese
Kannada
Kazakh
Kinyarwanda
Kirundi
Kongo
Korean
Krio (Sierra Leone)
Kurdish
Kurdish (Soranรฎ)
Kyrgyz
Laothian
Latin
Latvian
Lingala
Lithuanian
Lozi
Luganda
Luo
Luxembourgish
Macedonian
Malagasy
Malay
Malayalam
Maltese
Maori
Marathi
Mauritian Creole
Moldavian
Mongolian
Myanmar (Burmese)
Montenegrin
Nepali
Nigerian Pidgin
Northern Sotho
Norwegian
Norwegian (Nynorsk)
Occitan
Oriya
Oromo
Pashto
Polish
Portuguese (Brazil)
Portuguese (Portugal)
Punjabi
Quechua
Romanian
Romansh
Runyakitara
Russian
Samoan
Scots Gaelic
Serbian
Serbo-Croatian
Sesotho
Setswana
Seychellois Creole
Shona
Sindhi
Sinhalese
Slovak
Slovenian
Somali
Spanish
Spanish (Latin American)
Sundanese
Swahili
Swedish
Tajik
Tamil
Tatar
Telugu
Thai
Tigrinya
Tonga
Tshiluba
Tumbuka
Turkish
Turkmen
Twi
Uighur
Ukrainian
Urdu
Uzbek
Vietnamese
Welsh
Wolof
Xhosa
Yiddish
Yoruba
Zulu
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.