All language subtitles for 006 Understanding Type Inference_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
fa Persian Download
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, that we have learned about those base types

before I dive into functions and parameters,

I wanna talk about type inference.

In all those examples, which are listed here,

I always declared a variable with a type assigned.

And then in a second step, I set a value.

Now, often in programming, you do that in one step.

You create a variable

and you then already immediately assign an initial value.

So therefore here let's talk about type inference.

And let me show you what that is.

Let's say we have another variable down here.

The course variable. And in that course variable,

I wanna store the name of a course

like react the complete guide.

Like this.

Now, if I create this variable like this, and thereafter

I try to store a number for an example, the course ID

then you will see that I get an error,

because the type number is not assignable to type string.

But why am I getting this error?

After all, I don't define a type anywhere.

Well, here TypeScript used its powerful feature

of type inference.

By default, TypeScript tries to infer

as many types as possible.

So it tries to know which types are used

where, without you explicitly stating those types.

Which means that you need to write less code.

I could also set my type here as we learned it.

That would not be wrong, but it's redundant

because if you immediately initialize this variable

with a type TypeScript, will look at the value type here.

So it will see that we stored a string in that variable.

And it will then use that value type

as an inferred type for this variable.

And if you then try to assign a different type thereafter

you'll get an error, because of type inference.

And it is considered a good practice

and a good idea to embrace that type inference feature.

So to not unnecessarily specify the type

in addition, you can do that you can explicitly

state to type, but it's really redundant.

It just means more word from your side and therefore

you should not do that.

You should instead stick

to that type inference and use it whenever possible.

And that's another super important feature

which I wanted to highlight here.

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