-
Notifications
You must be signed in to change notification settings - Fork 14
Since TypeScript 2.0
, declaration files (.d.ts
files) can be downloaded with npm
. Here a sample to download declaration file for lodash
npm install --save @types/lodash
See The Future of Declaration Files for more information.
To avoid typing this npm
command manually, tsserver
provides the capability to execute this npm install @types/X
command by:
- tracking your dependencies declared in your
package.json
file. - and tracking your
import
from your TypeScript files.
This feature is called Automatic Type Acquisition. To enable ATA, you need:
-
npm
tooling. Since TypeScript IDE 1.2.0, the embedded node.js providesnpm
. -
enable ATA
. By default ATA is enabled, but you can disable it with Preferences. -
enable ATA
inside yourtsconfig.json
like this:
{
"typeAcquisition": {
"enable": true
}
}
ATA preferences
is available:
You can:
- disable ATA.
- enable telemetry to log in an Eclipse console the installed packages. It's helpful to understand problems.
Here a basic demo with ATA:
You can try enable ATA
with a little project.
- activate telemetry (not required) with Preferences.
- create a
tsconfig.json
like this:
{
"typeAcquisition": {
"enable": true
}
}
- create a
package.json
like this:
{
"name": "test-ata",
"version": "0.0.0",
"dependencies": {
"async": "*"
},
"author": "",
"license": "ISC"
}
- create a ts file like this:
import * as _ from "lodash";
When you will open the ts file, the tsserver
will start and ATA will download async
(from your package.json) and lodash
(from your ts file). If you have enable telemtry, you will see that inside the Eclipse console:
This download is done in the global cache (in Windows you can find it at C:\Users$user\AppData\Local\Microsoft\TypeScript\node_modules@types) and you will benefit with completion, hover, etc for async
and lodash
:
- TypeScript IDE
- New and Noteworthy