Definition File Locations
In this lesson, you will explore where to find definition files
You can get definition files from two different places.
Getting definition files directly from the JavaScript library #
The first one, which is getting popular, is directly from the JavaScript library when installing through NPM. If you look at the downloaded package, you might see index.d.ts in the folder of the library. If that is the case, it means that the author of the JavaScript library has provided the definition file. Having the library include the definition is the best case because the definition file is always in sync and up-to-date with the code.
The second way to get a definition file is to use NPM with @types/X
where X
is the name of the library you want the definition file from. The NPM package is not automatically valid for every library, but thousands and thousands of libraries got a package just for the type. The source code is from GitHub under the repository “DefinitelyTyped,” and it contains a collection of definition files across all libraries that contributors spend their time on, to keep the definition files up-to-date. Definition files are installed under the node_modules folder, under the folder @types
, inside the folder of the library requested. The TypeScript transpiler knows to look in this folder. The location can also be changed in the compiler configuration file.
Get hands-on with 1400+ tech skills courses.