Open-Source Wikis

/

TypeScript

/

Apps

/

typingsInstaller

microsoft/TypeScript

typingsInstaller

A small Node child process that fetches @types/* packages on behalf of tsserver. Powers TypeScript's Automatic Type Acquisition (ATA) for users who write plain JavaScript but still want IntelliSense from @types.

Purpose

When a user opens a .js file (or a project with allowJs and checkJs) in an editor backed by tsserver, the server discovers import statements and require calls referring to packages that lack ambient typings. It infers the package names, asks typingsInstaller to install matching @types/* packages into a per-user cache, and then returns to type-checking with the new declarations available.

typingsInstaller lives in three pieces:

Piece Source Role
Common scanning logic src/jsTyping/ Discovers candidate packages from JS files and package.json.
Generic installer base src/typingsInstallerCore/typingsInstaller.ts Cache management, diff-against-types-registry, install orchestration.
Node-specific entry src/typingsInstaller/nodeTypingsInstaller.ts Spawns npm via child_process.execSync.

Directory layout

src/jsTyping/                # ~630 lines: discovery
├── jsTyping.ts              # Package-name inference
├── shared.ts                # Shared IPC message types
└── types.ts

src/typingsInstallerCore/    # ~580 lines: install logic
└── typingsInstaller.ts

src/typingsInstaller/        # Node entry point
└── nodeTypingsInstaller.ts

How it works

sequenceDiagram
    participant Editor
    participant tsserver as src/server
    participant TIA as typingInstallerAdapter
    participant TI as typingsInstaller (child process)
    participant npm

    Editor->>tsserver: open foo.js
    tsserver->>tsserver: jsTyping.discover packages
    tsserver->>TIA: InstallTypings(["lodash", "express"])
    TIA->>TI: IPC message via stdio
    TI->>TI: filter against types-registry
    TI->>npm: npm install @types/lodash @types/express
    npm-->>TI: install completes
    TI->>TIA: TypingsInstalled event
    TIA->>tsserver: typings now available
    tsserver->>Editor: refreshed completions / diagnostics

Discovery happens in src/jsTyping/jsTyping.ts (discoverTypings). Inputs include the project's package.json, bower.json (legacy), and a list of imported module specifiers gleaned from JS source. Discovery filters against a types-registry JSON snapshot to avoid asking for types that don't exist on npm.

The installer caches results under the user's home directory (~/.cache/typescript/<version>/node_modules/@types/...). Subsequent tsserver sessions reuse the cache without contacting npm.

Key abstractions

Symbol File Role
discoverTypings src/jsTyping/jsTyping.ts Identify candidate @types packages
TypingsInstaller src/typingsInstallerCore/typingsInstaller.ts Orchestrates install, validates names, talks to a host
NodeTypingsInstaller src/typingsInstaller/nodeTypingsInstaller.ts Concrete subclass that runs npm
TypingsInstallerAdapter src/server/typingInstallerAdapter.ts tsserver-side IPC client

Recent commits (f1a9288c, c7a0ae10 in April 2026) tightened package-name validation in InstallPackageRequest to defend against requests for malformed names. The validation lives on both sides — the adapter and the installer — so a compromised tsserver couldn't ask the installer to run npm install on arbitrary input.

Integration points

  • Spawned by tsserver as a Node child_process.fork. Configurable: --typingsInstaller flag.
  • Talks to npm via execSync. The npm location is auto-detected by getDefaultNPMLocation in nodeTypingsInstaller.ts and can be overridden with --npmLocation.
  • Reads package.json via ts.sys.readFile for project metadata.
  • Writes a log file when --logFile <path> is passed (default off).

Entry points for modification

For ATA-related changes, edit src/jsTyping/jsTyping.ts for what to discover and src/typingsInstallerCore/typingsInstaller.ts for how to install. The IPC contract between server and installer is defined in src/jsTyping/shared.ts and src/server/typingInstallerAdapter.ts.

See also: systems/automatic-type-acquisition.

Built by Factory AutoWiki from public repository content. It is a generated preview for codebase exploration, not source-maintained documentation.

typingsInstaller – TypeScript wiki | Factory