You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: JavaScript-Language-Service-in-Visual-Studio.md
+15-15Lines changed: 15 additions & 15 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -4,9 +4,9 @@ Visual Studio 2017 provides a powerful JavaScript editing experience right out o
4
4
5
5
> The JavaScript language service in Visual Studio 2017 uses a new engine for the language service (former code name "Salsa"). Details are included here in this topic, and you might also want to read this [blog post](https://blogs.msdn.microsoft.com/visualstudio/2016/11/28/more-productive-javascript-in-visual-studio-2017-rc/). The new editing experience also mostly applies in VS Code. See the [VS Code docs](https://code.visualstudio.com/docs/languages/javascript) for more info.
6
6
7
-
For more information about the general IntelliSense functionality of Visual Studio, see [Using IntelliSense](https://docs.microsoft.com/en-us/visualstudio/ide/using-intellisense).
7
+
For more information about the general IntelliSense functionality of Visual Studio, see [Using IntelliSense](https://docs.microsoft.com/en-us/visualstudio/ide/using-intellisense).
8
8
9
-
## What's New in the JavaScript language service in Visual Studio 2017
9
+
## What's New in the JavaScript language service in Visual Studio 2017
10
10
-[Richer IntelliSense](#Rich)
11
11
-[Automatic acquisition of type definitions](#Auto)
12
12
-[Support for ES6 and beyond](#ES6)
@@ -21,11 +21,11 @@ TypeScript uses several sources to build up this information.
21
21
-[IntelliSense based on TypeScript Declaration Files](#TSDeclFiles)
22
22
23
23
#### <aname="TypeInference"></a>IntelliSense based on type inference
24
-
In JavaScript, most of the time there is no explicit type information available.
24
+
In JavaScript, most of the time there is no explicit type information available.
25
25
Luckily, it is usually fairly easy to deduce a type given the surrounding code context.
26
26
This process is called type inference.
27
27
28
-
For a variable or property, the type is typically the type of the value used to initialize it or the most recent value assignment.
28
+
For a variable or property, the type is typically the type of the value used to initialize it or the most recent value assignment.
29
29
30
30
```js
31
31
var nextItem =10;
@@ -35,7 +35,7 @@ nextItem = "box";
35
35
nextItem; // now we know nextItem is a string
36
36
```
37
37
38
-
For a function, the return type can be inferred from the return statements.
38
+
For a function, the return type can be inferred from the return statements.
39
39
40
40
For function parameters, there is currently no inference, but there are ways to work around this using JSDoc or TypeScript `.d.ts` files (see later sections).
41
41
@@ -70,7 +70,7 @@ x.b = false;
70
70
x. // <- "x" is shown as having properties a, b, and c of the types specified
71
71
```
72
72
73
-
As mentioned, function parameters are never inferred. However, using the JSDoc `@param` tag you can add types to function parameters as well.
73
+
As mentioned, function parameters are never inferred. However, using the JSDoc `@param` tag you can add types to function parameters as well.
74
74
75
75
```js
76
76
/**
@@ -80,8 +80,8 @@ function Foo(param1) {
80
80
this.prop= param1; // "param1" (and thus "this.prop") are now of type "string".
81
81
}
82
82
```
83
-
84
-
See [this doc](https://github.com/Microsoft/TypeScript/wiki/JsDoc-support-in-JavaScript) for the JsDoc annotations currently supported.
83
+
84
+
See [this doc](https://github.com/microsoft/TypeScript-wiki/blob/master/JSDoc-support-in-JavaScript.md) for the JsDoc annotations currently supported.
85
85
86
86
#### <aname="TsDeclFiles"></a> IntelliSense based on TypeScript Declaration Files
87
87
@@ -96,11 +96,11 @@ _**TypeScript declarations used in JavaScript**_
96
96
## <aname="Auto"></a> Automatic acquisition of type definitions
97
97
In the TypeScript world, most popular JavaScript libraries have their APIs described by `.d.ts` files, and the most common repository for such definitions is on [DefinitelyTyped](https://github.com/DefinitelyTyped/DefinitelyTyped).
98
98
99
-
By default, the Salsa language service will try to detect which JavaScript libraries are in use and automatically download and reference the corresponding `.d.ts` file that describes the library in order to provide richer IntelliSense. The files are downloaded to a cache located under the user folder at `%LOCALAPPDATA%\Microsoft\TypeScript`.
99
+
By default, the Salsa language service will try to detect which JavaScript libraries are in use and automatically download and reference the corresponding `.d.ts` file that describes the library in order to provide richer IntelliSense. The files are downloaded to a cache located under the user folder at `%LOCALAPPDATA%\Microsoft\TypeScript`.
100
100
101
101
> This feature is **disabled** by default if using a `tsconfig.json` configuration file, but may be set to enabled as outlined further below).
102
102
103
-
Currently auto-detection works for dependencies downloaded from npm (by reading the `package.json` file), Bower (by reading the `bower.json` file), and for loose files in your project that match a list of roughly the top 400 most popular JavaScript libraries. For example, if you have `jquery-1.10.min.js` in your project, the file `jquery.d.ts` will be fetched and loaded in order to provide a better editing experience. This `.d.ts` file will have no impact on your project.
103
+
Currently auto-detection works for dependencies downloaded from npm (by reading the `package.json` file), Bower (by reading the `bower.json` file), and for loose files in your project that match a list of roughly the top 400 most popular JavaScript libraries. For example, if you have `jquery-1.10.min.js` in your project, the file `jquery.d.ts` will be fetched and loaded in order to provide a better editing experience. This `.d.ts` file will have no impact on your project.
104
104
105
105
If you do not wish to use auto-acquisition, disable it by adding a configuration file as outlined below. You can still place definition files for use directly within your project manually.
106
106
@@ -118,7 +118,7 @@ The required settings for the tsconfig file are outlined below:
118
118
By default this is `false`, as TypeScript compiles to JavaScript, and this is necessary to avoid the compiler including files it just compiled.
119
119
-`outDir`: This should be set to a location not included in the project, in order that the emitted JavaScript files are not detected and then included in the project (see `exclude` below).
120
120
-`module`: If using modules, this setting tells the compiler which module format the emitted code should use (e.g. `commonjs` for Node or bundlers such as Browserify).
121
-
-`exclude`: This setting states which folders not to include in the project.
121
+
-`exclude`: This setting states which folders not to include in the project.
122
122
The output location, as well as non-project folders such as `node_modules` or `temp`, should be added to this setting.
123
123
-`enableAutoDiscovery`: This setting enables the automatic detection and download of definition files as outlined above.
124
124
-`compileOnSave`: This setting tells the compiler if it should recompile any time a source file is saved in Visual Studio.
JavaScript in Visual Studio 2017 has rich support for the JSX syntax. JSX is a syntax set that allows HTML tags within JavaScript files.
184
+
JavaScript in Visual Studio 2017 has rich support for the JSX syntax. JSX is a syntax set that allows HTML tags within JavaScript files.
185
185
186
186
The illustration below shows a React component defined in the `comps.tsx` TypeScript file, and then this component being used from the `app.jsx` file, complete with IntelliSense for completions and documentation within the JSX expressions.
187
187
You don't need TypeScript here, this specific example just happens to contain some TypeScript code as well.
@@ -198,7 +198,7 @@ var comps_1 = require('./comps');
198
198
var x =React.createElement(comps_1.RepoDisplay, {description:"test"});
199
199
```
200
200
201
-
## Notable Changes from VS 2015
201
+
## Notable Changes from VS 2015
202
202
As Salsa is a completely new language service, there are a few behaviors that will be different or absent from the previous experience.
203
203
The most notable of these changes are the replacement of VSDoc with JSDoc, the removal of custom `.intellisense.js` extensions, and limited IntelliSense for specific code patterns.
204
204
@@ -219,7 +219,7 @@ You can learn more about declaration (`.d.ts`) file authoring [here](http://www.
219
219
220
220
### Unsupported patterns
221
221
Because the new language service is powered by static analysis rather than an execution engine (read [this issue](https://github.com/Microsoft/TypeScript/issues/4789) for information of the differences), there are a few JavaScript patterns that no longer can be detected.
222
-
The most common pattern is the "expando" pattern.
222
+
The most common pattern is the "expando" pattern.
223
223
Currently the language service cannot provide IntelliSense on objects that have properties tacked on after declaration.
0 commit comments