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: docs/ide/javascript-intellisense.md
+6-6Lines changed: 6 additions & 6 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -46,7 +46,7 @@ TypeScript uses several sources to build up this information:
46
46
47
47
## IntelliSense based on type inference
48
48
49
-
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.
50
50
This process is called type inference.
51
51
52
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.
@@ -61,9 +61,9 @@ nextItem; // now we know nextItem is a string
61
61
62
62
For a function, the return type can be inferred from the return statements.
63
63
64
-
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).
65
65
66
-
Additionally, there is special inference for the following:
66
+
Additionally, there's special inference for the following:
67
67
68
68
- "ES3-style" classes, specified using a constructor function and assignments to the prototype property.
69
69
- CommonJS-style module patterns, specified as property assignments on the `exports` object, or assignments to the `module.exports` property.
@@ -82,7 +82,7 @@ exports.Foo = Foo;
82
82
83
83
## IntelliSense based on JSDoc
84
84
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 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:
86
86
87
87
```js
88
88
/**
@@ -108,7 +108,7 @@ See the JSDoc information in [Type Checking JavaScript Files](https://www.typesc
108
108
109
109
## IntelliSense based on TypeScript declaration files
110
110
111
-
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.
112
112
113
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).
114
114
@@ -121,7 +121,7 @@ In the TypeScript world, most popular JavaScript libraries have their APIs descr
121
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*.
122
122
123
123
> [!NOTE]
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 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.
125
125
126
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.
0 commit comments