Relationship between the version of node.js and the version of @types/node
Asked Answered
D

1

100

I'm just started using node and wanted to try it with typescript. I did an npm install @types/node and the latest version was 7.0.4:

$ npm install @types/node
[email protected] /home/wink/prgs/test-simple-node-typescript
└── @types/[email protected] 

Where as the latest version of node is 7.5.0:

$ node --version
v7.5.0

What is the relationship between the version of node.js and that of @types/node?

Detrain answered 4/2, 2017 at 0:47 Comment(5)
I think types declaration for node has not changed from version 7.0.0. There was just 4 minor updates to typings.Delude
@misaz, thanks for the info, but how would I know that @types/node version 7.0.4 === node version 7.5.0? Also, when I went to the DefinitelyTyped issues I saw Merge node changes from @types org which left me feeling that things were out of date or incorrect.Detrain
Typings is for node 7.0.0, 7.1.0, 7.2.0, ... the same. When major version (eg. 7.0.0) is released then no change in API is allowed in minor update. Because this 7.1.0 has the same typings as 7.0.0. version 7.2.0 too. version 7.4.0 too. ... Typings 7.0.0 was released for 7.0.0 then he found some bugs in typings or needs to improve and was forced to release new typings 7.0.1, then 7.0.2, then 7.0.3, then 7.0.4. Node series 7.X.Y has all typings version 7.0.Z. X != Y != Z. Dependency between node and typing version is only in first number.Delude
If anyone needs it, I imagine a good way to deal with this is to update your package.json file and set "@types/node" to "<7.5.0" (and if you're on another version, replace 7.5.0 with whatever you're using). PS: That was really helpful, thanks @DeludeCondemnation
the question can be generalized to any DefinitelyTyped package. see How can I find what versions of a @types package from DefinitelyTyped work with what versions of the actual package?Laclos
C
48

Simply, the major version and minor version tagged in the semver string of @types/node is exactly corresponding to the node's version.

If you check the index.d.ts file of @types/node in DefinitelyTyped repository, you'll see what type of node is this declaration file for through the first line comment at the top of the file:

// Type definitions for non-npm package Node.js 16.11
// Project: https://nodejs.org/
....
Coonhound answered 19/9, 2018 at 10:59 Comment(9)
This looks true for newer versions, but old versions seem to have a different numbering system. Version 7 of @types/node, for example, goes from 7.0.0 through 7.0.71 (as of the time I wrote this comment), and then jumps to 7.10.0. So it looks like the 7.0.x series correlates to the node versions 7.0 through 7.9.Hobart
For Node 14: github.com/DefinitelyTyped/DefinitelyTyped/blob/master/types/…Shortage
For Node 16: github.com/DefinitelyTyped/DefinitelyTyped/blob/master/types/…Jell
I think this never holds true, e.g. for NodeJS version 16.17.1, there is no @types/[email protected].*...Tearing
Yes, for lts 18.18.0 there is no corresponding @types/nodeAndino
@coler-j, try npm view @types/node versions --json | grep '"18.18.' | sort -rV | head -n 1 (returns 18.18.9 at the moment)Siccative
@ChristianUlbrich, huh, yeah, looks like it jumped from 16.11 to 16.18, maybe there were no type changes in the missing minor releases.Siccative
More here: #11949919Siccative
In github.com/DefinitelyTyped/DefinitelyTyped/blob/master/types/… I'm no longer able to see Node.js version mentioned. Am I missing anything here?Hadron

© 2022 - 2024 — McMap. All rights reserved.