All language subtitles for 007 Using Union 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 type inference is great.

And in general, up to this point

we already learned quite a bit

about TypeScript and its core types.

But up to this point, we also always had the scenario

that every variable took just one type.

So we always had just one possible type that could be stored

in a variable,

just a number or just a string or just a boolean.

And often that is what you need,

but sometimes you want to allow multiple, different types.

Let's say here for the course

we might be fine with storing a string in there

but maybe storing a course ID

as a number should also be correct.

It really depends on what you're building.

It's not unrealistic that we could have a variable

where both a string, as well as a number should be allowed

or that you have some variable

which should allow two different kinds of objects.

And for this scenario, that you have more than one type

which you want to allow

you have a feature called union types.

A union type is a type definition that allows more

than one type.

You add it like any other type assignment by adding a colon

after the variable name,

on the left side of the equal sign,

and then your type.

Now I mentioned that explicitly setting string

again here would be redundant, but it's not redundant

if you don't want to use the type inference here.

But if you instead want to specify such a union type,

hence allowing multiple types, you set up such a union type

by adding a pipe symbol after your first type

and then adding another type, like number.

And you can have as many types

which you want to allow here as needed,

but here I just want to have string or number.

And now you see that that error

which we had down here before is gone,

because now we are allowing a number alternatively

to a string value.

And of course you can use such a union type anywhere

where you have a type assignment,

not just when you're using type inference.

I could also use a union type up here

allowing username to be a string or

let's say an array of strings, for example

so that we have first and last name

in an array, for example.

That's also something I could allow here.

Union types are a never key TypeScript feature

which allows you to define more flexible values and types.

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