Skip to content
Angelo edited this page Jan 30, 2017 · 3 revisions

Automatic Type Acquisition (ATA)

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:

{
	"typeAcquisition": {
		"enable": true
	}
}

Preferences

ATA preferences is available:

ATA preferences

You can:

  • disable ATA.
  • enable telemetry to log in an Eclipse console the installed packages. It's helpful to understand problems.

Demo

Here a basic demo with ATA:

ATA Demo

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:

ATA 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:

ATA With Loadash