1 00:00:00,730 --> 00:00:05,510 In the last video we installed a fake module but we very quickly saw a warning around it. 2 00:00:05,510 --> 00:00:10,970 So if I hover over this right here I see somebody and says cannot find declaration file for module faker. 3 00:00:11,000 --> 00:00:13,370 So let's talk about what that's about. 4 00:00:13,370 --> 00:00:15,460 First off a quick diagram. 5 00:00:15,460 --> 00:00:15,700 All right. 6 00:00:15,710 --> 00:00:20,150 So just to make sure things are really clear whenever you and I are writing typescript code we are free 7 00:00:20,150 --> 00:00:26,200 to make use of JavaScript or more precisely javascript libraries as much as we want to. 8 00:00:26,270 --> 00:00:33,140 So we can install common javascript libraries into any types good project using NPM or we could even 9 00:00:33,140 --> 00:00:39,100 reference JavaScript files that you and I write ourselves inside of our project from typescript code. 10 00:00:39,380 --> 00:00:41,870 But there's one little caveat here. 11 00:00:41,870 --> 00:00:48,770 Remember typescript wants to check your code and it checks your code by the use of types types wants 12 00:00:48,770 --> 00:00:51,070 to know all the different functions that you have. 13 00:00:51,080 --> 00:00:55,390 What different type of arguments they take and what type of value they return. 14 00:00:55,420 --> 00:00:59,600 In general he wants to know all the different types of data that are flowing around your application. 15 00:00:59,690 --> 00:01:04,520 If typescript doesn't have this information then it can not completely check your code. 16 00:01:04,640 --> 00:01:07,830 So we start to think about using JavaScript code inside of our project. 17 00:01:07,850 --> 00:01:13,580 Naturally all javascript code we write or make use of is not going to have any type information attached 18 00:01:13,580 --> 00:01:18,950 to it in typescript can't really automatically figure out what different types of values are floating 19 00:01:18,980 --> 00:01:20,990 around javascript code. 20 00:01:20,990 --> 00:01:26,680 So to fix this problem typescript has the idea of type definition files. 21 00:01:26,870 --> 00:01:31,280 You can think of a type definition file as kind of an adapter between typescript code that you and I 22 00:01:31,280 --> 00:01:36,860 write in javascript libraries that we try to work with it type definition file is going to tell the 23 00:01:36,860 --> 00:01:42,350 typescript compiler all the different functions that are available inside this javascript library. 24 00:01:42,350 --> 00:01:47,160 What type of argument they take and what type of value those functions return. 25 00:01:47,180 --> 00:01:52,100 So once again you can think of these type definition files as like an adapter layer of sorts. 26 00:01:53,230 --> 00:01:58,050 Sometimes type definition files will get installed automatically when you install a javascript library. 27 00:01:58,120 --> 00:02:02,710 So for example if you recall that axiom is project we worked on at the very start of this course. 28 00:02:02,710 --> 00:02:07,030 We never did anything related to type definition definition files. 29 00:02:07,030 --> 00:02:12,430 That's because axioms by default includes a type definition File for us. 30 00:02:12,430 --> 00:02:17,980 However right now we are making use of the faker module which does not include a type definition file 31 00:02:18,930 --> 00:02:24,150 so we have to install a type definition file manually if it is not included for us. 32 00:02:24,240 --> 00:02:29,520 It might sound really challenging to know when a type definition is file is included or not included 33 00:02:29,790 --> 00:02:31,800 but basically it's gonna be a really straightforward. 34 00:02:31,800 --> 00:02:35,800 If you ever try to make use of a module and you see that warning we just saw right here. 35 00:02:35,850 --> 00:02:41,950 That means you need to install the type declaration file once we understand that we need to install 36 00:02:41,950 --> 00:02:42,670 that file. 37 00:02:42,670 --> 00:02:44,650 It's a really simple process. 38 00:02:44,650 --> 00:02:46,480 So here's what's gonna happen. 39 00:02:46,660 --> 00:02:50,740 All these type definition files are already publicly available for you. 40 00:02:50,770 --> 00:02:55,480 I shouldn't say all of them but the vast majority for popular libraries have already been created. 41 00:02:55,480 --> 00:03:00,610 So there is already a type definition file out there that has been created by some random person to 42 00:03:00,610 --> 00:03:05,020 work with the faker library to install that type definition file. 43 00:03:05,020 --> 00:03:08,700 We're going to reach into a project called definitely typed. 44 00:03:08,890 --> 00:03:13,300 That's the name of the project that includes all these pre created or pre generated type definition 45 00:03:13,300 --> 00:03:18,810 files in general to get any of these type definition files from definitely pi typed. 46 00:03:18,820 --> 00:03:24,190 We're always going to install an NPM module that generally is going to be named something like at types 47 00:03:24,400 --> 00:03:28,180 slash and then the name of the library that we're trying to make use of. 48 00:03:28,180 --> 00:03:32,920 So for us it would be at types slash faker as a quick example. 49 00:03:32,920 --> 00:03:35,970 Let's try looking up that module on NPM right now. 50 00:03:36,010 --> 00:03:39,070 So back inside my browser over here at NPM J Ask.com. 51 00:03:39,190 --> 00:03:45,460 I can do a search for at types slash faker and I'll see the typescript definition file appear for that 52 00:03:45,460 --> 00:03:52,830 library so we can scroll down a little bit and you'll see some details inside of here where it says 53 00:03:52,830 --> 00:03:59,240 very clearly that this file or this project has been generated from the definitely typed project so 54 00:03:59,250 --> 00:04:00,290 we can definitely typed. 55 00:04:00,280 --> 00:04:05,070 Anytime you see that term they're talking about type definition files for JavaScript libraries. 56 00:04:06,470 --> 00:04:06,710 All right. 57 00:04:06,710 --> 00:04:10,850 So once again to fix up this whole big issue all we have to do is install that type definition file 58 00:04:10,850 --> 00:04:12,190 for faker. 59 00:04:12,290 --> 00:04:14,870 So I'm going to flip back over to my terminal one more time. 60 00:04:14,990 --> 00:04:23,300 I'm going to do an npm install at types slash faker these files are always extremely small because there's 61 00:04:23,310 --> 00:04:26,400 just a little bit of code to describe the different types inside that library. 62 00:04:26,400 --> 00:04:34,870 So once it is installed we can then start backup partial once more with Passel index HMO. 63 00:04:34,880 --> 00:04:35,150 All right. 64 00:04:35,150 --> 00:04:39,860 Once that's all done I can flip back over to my editor and you'll now notice that that little warning 65 00:04:39,890 --> 00:04:40,750 is gone. 66 00:04:40,790 --> 00:04:44,090 I still see a warning here saying that fakers declared butts values never read. 67 00:04:44,090 --> 00:04:45,500 That's totally fine. 68 00:04:45,500 --> 00:04:50,360 More importantly we got rid of that other error or that other warning around a missing type definition 69 00:04:50,360 --> 00:04:51,630 file. 70 00:04:51,790 --> 00:04:52,020 OK. 71 00:04:52,050 --> 00:04:53,630 So that's it for type definition files. 72 00:04:53,640 --> 00:04:58,860 Again remember vast majority of time that you are using a javascript project inside of your typescript 73 00:04:58,860 --> 00:04:59,320 code. 74 00:04:59,400 --> 00:05:04,860 You might have to install that type definition file some javascript libraries include that type definition 75 00:05:04,860 --> 00:05:06,090 file by default. 76 00:05:06,090 --> 00:05:11,460 Other ones like less popular libraries in general are not going to include it automatically so you will 77 00:05:11,460 --> 00:05:13,790 have to install it separately. 78 00:05:13,790 --> 00:05:14,000 All right. 79 00:05:14,010 --> 00:05:16,490 Let's take a pause right here and we'll continue in the next video.