-
Notifications
You must be signed in to change notification settings - Fork 12.6k
Typings for npm packages
TypeScript 1.6 has introduced new way of resolving module names that mimics the Node.js module resolution algorithm. This means the TypeScript compiler can currently load typings that are bundled with npm packages. The compiler will try to discover typings for module "foo"
using the following set of rules:
-
Try to load the
package.json
file located in the appropriate package folder (node_modules/foo/
). If present,read the path to the typings file described in the"typings"
field. For example, in the followingpackage.json
, the compiler will resolve the typings atnode_modules/foo/lib/foo.d.ts
{ "name": "foo", "author": "Vandelay Industries", "version": "1.0.0", "main": "./lib/foo.js", "typings": "./lib/foo.d.ts" }
-
Try to load a file named
index.d.ts
located in the package folder (node_modules/foo/
) - this file should contain typings for the package.
The precise algorithm for module resolution can be found here
- be a
.d.ts
file - be an external module
- not have triple-slash references
The rationale is that typings should not bring new compilable items to the set of compiled files; otherwise actual implementation files in the package can be overwritten during compilation. Additionally, loading typings should not pollute global scope by bringing potentially conflicting entries from different version of the same library
News
Debugging TypeScript
- Performance
- Performance-Tracing
- Debugging-Language-Service-in-VS-Code
- Getting-logs-from-TS-Server-in-VS-Code
- JavaScript-Language-Service-in-Visual-Studio
- Providing-Visual-Studio-Repro-Steps
Contributing to TypeScript
- Contributing to TypeScript
- TypeScript Design Goals
- Coding Guidelines
- Useful Links for TypeScript Issue Management
- Writing Good Design Proposals
- Compiler Repo Notes
- Deployment
Building Tools for TypeScript
- Architectural Overview
- Using the Compiler API
- Using the Language Service API
- Standalone Server (tsserver)
- TypeScript MSBuild In Depth
- Debugging Language Service in VS Code
- Writing a Language Service Plugin
- Docker Quickstart
FAQs
The Main Repo