Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does /// <reference path="jquery-1.8.3.js" /> actually do?

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.

like image 792
Neo Avatar asked Nov 21 '16 17:11

Neo


2 Answers

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.

like image 118
Gavin Avatar answered Nov 14 '22 13:11

Gavin


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.

like image 45
ssube Avatar answered Nov 14 '22 13:11

ssube