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
@@ -42,7 +46,7 @@ TypeScript uses several sources to build up this information:
42
46
43
47
## IntelliSense based on type inference
44
48
45
-
In JavaScript, most of the time there is no explicit type information available. Luckily, it's usually fairly easy to figure out a type given the surrounding code context.
49
+
In JavaScript, most of the time there's no explicit type information available. Luckily, it's usually easy to figure out a type given the surrounding code context.
46
50
This process is called type inference.
47
51
48
52
For a variable or property, the type is typically the type of the value used to initialize it or the most recent value assignment.
@@ -57,9 +61,9 @@ nextItem; // now we know nextItem is a string
57
61
58
62
For a function, the return type can be inferred from the return statements.
59
63
60
-
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).
64
+
For function parameters, there's currently no inference, but there are ways to work around this using JSDoc or TypeScript *.d.ts* files (see later sections).
61
65
62
-
Additionally, there is special inference for the following:
66
+
Additionally, there's special inference for the following:
63
67
64
68
- "ES3-style" classes, specified using a constructor function and assignments to the prototype property.
65
69
- CommonJS-style module patterns, specified as property assignments on the `exports` object, or assignments to the `module.exports` property.
@@ -78,7 +82,7 @@ exports.Foo = Foo;
78
82
79
83
## IntelliSense based on JSDoc
80
84
81
-
Where type inference doesn't provide the desired type information (or to support documentation), type information may be provided explicitly via JSDoc annotations. For example, to give a partially declared object a specific type, you can use the `@type` tag as shown below:
85
+
Where type inference doesn't provide the desired type information (or to support documentation), type information may be provided explicitly via JSDoc annotations. For example, to give a partially declared object a specific type, you can use the `@type` tag as shown here:
82
86
83
87
```js
84
88
/**
@@ -104,7 +108,7 @@ See the JSDoc information in [Type Checking JavaScript Files](https://www.typesc
104
108
105
109
## IntelliSense based on TypeScript declaration files
106
110
107
-
Because JavaScript and TypeScript are based on the same language service, they are able to interact in a rich way. For example, JavaScript IntelliSense can be provided for values declared in a *.d.ts* file (see [TypeScript documentation](https://www.typescriptlang.org/docs/handbook/declaration-files/introduction.html)), and types such as interfaces and classes declared in TypeScript are available for use as types in JSDoc comments.
111
+
Because JavaScript and TypeScript are based on the same language service, they're able to interact in a rich way. For example, JavaScript IntelliSense can be provided for values declared in a *.d.ts* file (see [TypeScript documentation](https://www.typescriptlang.org/docs/handbook/declaration-files/introduction.html)), and types such as interfaces and classes declared in TypeScript are available for use as types in JSDoc comments.
108
112
109
113
Below, we show a simple example of a TypeScript definition file providing such type information (via an interface) to a JavaScript file in the same project (using a `JSDoc` tag).
110
114
@@ -117,10 +121,16 @@ In the TypeScript world, most popular JavaScript libraries have their APIs descr
117
121
By default, the language service tries to detect which JavaScript libraries are in use, and then 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*.
118
122
119
123
> [!NOTE]
120
-
> This feature is **disabled** by default if you're using a *tsconfig.json* configuration file, but may be set to enabled as outlined further below.
124
+
> This feature is **disabled** by default if you're using a *tsconfig.json* configuration file, but may be set to enabled as outlined further in this section.
121
125
122
126
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.
123
127
128
+
## Configure IntelliSense
129
+
130
+
You can use change the behavior of IntelliSense statement completion by selecting **Tools > Options > Text Editor > JavaScript/TypeScript > IntelliSense > General**.
131
+
132
+
When you select **Only use Tab or Enter to commit**, the JavaScript code editor appends statements with items selected in the completion list only after you choose the **Tab** or **Enter** key. When you deselect this check box, other characters – such as a period, comma, colon, open parenthesis, and open brace ({) – can also append statements with the selected items.
0 commit comments