I see this line of code in some of the JavaScript Files I work with, at the very top of the file ( first line ), but its not clear to me exactly what this does.
Google wasn't much help on this.
/// <reference path="jquery-1.8.3.js" />
What is the purpose of it?
To add more details, I am using Visual Studio 2015.
This is most likely for Visual Studio's JavaScript intellisense. Mads Kristensen has a nice article you can read to learn more about the history of this and how to use it correctly.
That is a triple-slash directive for the Typescript compiler. Since tsc
will happily compile JS as well, this should work in either language and will reference a dependency.
The /// <reference .../>
directive shows a dependency (for compiler symbols) without necessarily importing and actually loading the file. That is useful when you have a large library (like React) that exports a lot of interfaces or type
symbols, but you don't want to actually include (since they might be vendored at runtime). From the docs:
The /// directive is the most common of this group. It serves as a declaration of dependency between files.
Triple-slash references instruct the compiler to include additional files in the compilation process.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With