In the last video we installed a fake module but we very quickly saw a warning around it.
So if I hover over this right here I see somebody and says cannot find declaration file for module faker.
So let's talk about what that's about.
First off a quick diagram.
All right.
So just to make sure things are really clear whenever you and I are writing typescript code we are free
to make use of JavaScript or more precisely javascript libraries as much as we want to.
So we can install common javascript libraries into any types good project using NPM or we could even
reference JavaScript files that you and I write ourselves inside of our project from typescript code.
But there's one little caveat here.
Remember typescript wants to check your code and it checks your code by the use of types types wants
to know all the different functions that you have.
What different type of arguments they take and what type of value they return.
In general he wants to know all the different types of data that are flowing around your application.
If typescript doesn't have this information then it can not completely check your code.
So we start to think about using JavaScript code inside of our project.
Naturally all javascript code we write or make use of is not going to have any type information attached
to it in typescript can't really automatically figure out what different types of values are floating
around javascript code.
So to fix this problem typescript has the idea of type definition files.
You can think of a type definition file as kind of an adapter between typescript code that you and I
write in javascript libraries that we try to work with it type definition file is going to tell the
typescript compiler all the different functions that are available inside this javascript library.
What type of argument they take and what type of value those functions return.
So once again you can think of these type definition files as like an adapter layer of sorts.
Sometimes type definition files will get installed automatically when you install a javascript library.
So for example if you recall that axiom is project we worked on at the very start of this course.
We never did anything related to type definition definition files.
That's because axioms by default includes a type definition File for us.
However right now we are making use of the faker module which does not include a type definition file
so we have to install a type definition file manually if it is not included for us.
It might sound really challenging to know when a type definition is file is included or not included
but basically it's gonna be a really straightforward.
If you ever try to make use of a module and you see that warning we just saw right here.
That means you need to install the type declaration file once we understand that we need to install
that file.
It's a really simple process.
So here's what's gonna happen.
All these type definition files are already publicly available for you.
I shouldn't say all of them but the vast majority for popular libraries have already been created.
So there is already a type definition file out there that has been created by some random person to
work with the faker library to install that type definition file.
We're going to reach into a project called definitely typed.
That's the name of the project that includes all these pre created or pre generated type definition
files in general to get any of these type definition files from definitely pi typed.
We're always going to install an NPM module that generally is going to be named something like at types
slash and then the name of the library that we're trying to make use of.
So for us it would be at types slash faker as a quick example.
Let's try looking up that module on NPM right now.
So back inside my browser over here at NPM J Ask.com.
I can do a search for at types slash faker and I'll see the typescript definition file appear for that
library so we can scroll down a little bit and you'll see some details inside of here where it says
very clearly that this file or this project has been generated from the definitely typed project so
we can definitely typed.
Anytime you see that term they're talking about type definition files for JavaScript libraries.
All right.
So once again to fix up this whole big issue all we have to do is install that type definition file
for faker.
So I'm going to flip back over to my terminal one more time.
I'm going to do an npm install at types slash faker these files are always extremely small because there's
just a little bit of code to describe the different types inside that library.
So once it is installed we can then start backup partial once more with Passel index HMO.
All right.
Once that's all done I can flip back over to my editor and you'll now notice that that little warning
is gone.
I still see a warning here saying that fakers declared butts values never read.
That's totally fine.
More importantly we got rid of that other error or that other warning around a missing type definition
file.
OK.
So that's it for type definition files.
Again remember vast majority of time that you are using a javascript project inside of your typescript
code.
You might have to install that type definition file some javascript libraries include that type definition
file by default.
Other ones like less popular libraries in general are not going to include it automatically so you will
have to install it separately.
All right.
Let's take a pause right here and we'll continue in the next video.