How to manually update a deprecated typings package

Travesty3 picture Travesty3 · Jul 22, 2016 · Viewed 8.9k times · Source

I have a NodeJS application that I'm writing in TypeScript. It uses many Node packages. Not all of these packages have Typescript definitions, so I use Typings to get the separate definition files.

When I deploy my application to the production server, I have a Git hook that runs npm install, typings install, and tsc, since these are not included in the Git repository.

When a new version of a Typings definition file is released on DefinitelyTyped, I get warnings when it runs typings install that my definitions files are deprecated (updated, replaced, or removed):

typings WARN deprecated 6/30/2016: "registry:dt/bluebird#2.0.0+20160319051630" is deprecated (updated, replaced or removed)
typings WARN deprecated 7/5/2016: "registry:dt/knex#0.0.0+20160622193910" is deprecated (updated, replaced or removed)
typings WARN deprecated 7/20/2016: "registry:dt/node#6.0.0+20160613154055" is deprecated (updated, replaced or removed)
typings WARN deprecated 7/19/2016: "registry:dt/lodash#3.10.0+20160619033623" is deprecated (updated, replaced or removed)

What can be done about this? Is there an easy way to update them all? It looks like the typings.json file specifies a version number for the package after the # sign and a date after the + sign. If a new definitions file gets uploaded to DefinitelyTyped, isn't it usually safe to assume it's more accurate or more complete than the previous version?

Is there even any sanctioned way to update these manually, aside from typings uninstall --save followed by typings install --save for each package? Seems like a hassle, and there should be some easy way, something like typings update [package-name].

Answer

Koslun picture Koslun · Jul 25, 2016

Easy in TypeScript 2.0

Should also be mentioned that TypeScript 2.0, officially released in September 2016, has an easier solution integrated into npm (in collaboration with the Typings author and TSD authors). Where you essentially get the Definitely Typed packages as @types/packageName:

npm install --save packageName @types/packageName

while also being able to automatically get types from npm packages directly. Thus enabling you to simply use package.json and npm to directly manage your type definitions. In which case

npm update

will get exactly the behavior you originally requested.

Check the beta announcement blog post and official Typescript documentation for more information.


Breaking changes from @types don't trigger warnings

Would however want to note that a member in the Typescript team (Ryan Cavanaugh) mentioned in the comment section of TypeScript's Beta announcement that at least the current version of the Beta he was referring to did not warn for out-of-date Type Definitions. Even for semver major updates. Meaning if you wanted type definitions for lodash version 4 and instead got for lodash version 3, there would be no warning. Thus getting the type definition for a library that has gone through breaking changes. Just something to potentially have in mind (EDIT: Have personally not yet confirmed whether this is the case for the final 2.0 release.).

No update command

There is no update command, there is an issue on Typings about it, containing both unix and powershell scripts to automatically do some kind of update as well.

Specific install command

As you can see in the CLI options, you can however update the type definition for a specific package with a specific source and semver range.

If the source is Definitely Typed you would prefix the package with dt~. While if you have the semver version ^3.10.0, you would further suffix the package name with @^3.10.0.

Depending on if it's a regular or development dependency you would also add --save or --save-dev respectively. While you would further also add --global if it's a global such dependency. This should be readable in the typings.json file

To update the lodash package you mentioned above to the latest type definition with semver version ^3.10.0 you would write:

typings install dt~lodash@^3.10.0 --save

or

typings install dt~lodash@^3.10.0 --save --global

if it's a global dependency.

This will update the hash and date of typings.json and install that latest definition for the given semver range. While if there is no update to be found, there is no change to the file. If you are set on automating this update process you could thus write a script which tries to do these updates regardless.

Caveats

Note that Definitely Typed type definitions not necessarily always are correctly tagged with versions. Potentially completely lacking tagged versions or having big gaps between them. Could for instance also be that an untagged version is newer than the latest tagged version, this is currently the case for lodash at Definitely Typed (25th June, 2016).

You can easily discover which tagged versions exist for a given package at a given source with:

typings view <source>~<package> --versions

for the package lodash with Definitely Typed as the source it would thus be:

typings view dt~lodash --versions

To see untagged versions that could be more up-to-date I think you have to actually inspect the corresponding directory at the Definitely Typed repo, where it could be mentioned in the latest commit or stated at the top of the file.