Simple Solution in TypeScript 2.0
In addition to the official release of TypeScript 2.0 in September 2016, it's worth noting that there is now an easier solution integrated into npm
. This collaboration with Typings author and TSD authors allows you to obtain the Definitely Typed packages as @types/packageName
by simply running:
npm install --save packageName @types/packageName
You can also automatically fetch types from npm packages directly using your package.json
file and npm
commands. So, when you run
npm update
you will achieve the desired result without any complications.
For more information, refer to the beta announcement blog post and the official Typescript documentation.
No Warnings for Breaking Changes in @types
The current version of TypeScript Beta may not warn you about out-of-date Type Definitions even for major updates, as mentioned by a member of the TypeScript team in the comment section of TypeScript's Beta announcement. Keep this in mind to avoid potential issues with type definitions for libraries undergoing breaking changes (Note: Confirmation needed for final 2.0 release).
Lack of Update Command
There isn't an update command available, but there is an issue on Typings discussing automatic updating using scripts.
Updating Specific Packages
You can update type definitions for specific packages based on source and semver range with CLI options. Use dt~
prefix for Definitely Typed sources and specify versions like @^3.10.0
accordingly. Add --save
or --save-dev
depending on dependency type, and --global
if it's a global dependency as indicated in typings.json
.
To update the lodash package to the latest type definition version ^3.10.0
, use:
typings install dt~lodash@^3.10.0 --save
or
typings install dt~lodash@^3.10.0 --save --global
This will update typings.json and install the latest definition within the specified semver range. Automate updates if necessary with a custom script.
Considerations
Keep in mind that Definitely Typed type definitions may not always have accurate tagged versions, potentially leading to discrepancies. Check available versions for a package at a given source using:
typings view <source>~<package> --versions
For example, to check versions for lodash from Definitely Typed, use:
typings view dt~lodash --versions
For untagged versions that could be more up-to-date, inspect the repository directories where relevant information may be provided in commit messages or files.