Is adding a d.ts file to a JavaScript npm package a breaking change by SemVer rules?

249 views Asked by At

If I had a purely JavaScript npm package with no dependence on TypeScript, and I wanted to add a d.ts type declaration file to it, along with a new "types" property in the package.json pointing to the file, would that be considered a breaking change? Would it necessitate a major version bump according to SemVer?

I could see either way, since it's not affecting the JavaScript at all, and it doesn't break the APIs of anything. However if someone is using the library in a TypeScript project and has made their own d.ts types for the library, it could conflict with those types, like with a "Duplicate Identifier" error.

1

There are 1 answers

0
Peter Lehnhardt On BEST ANSWER

SemVer states

Given a version number MAJOR.MINOR.PATCH, increment the:

  1. MAJOR version when you make incompatible API changes,
  2. MINOR version when you add functionality in a backwards compatible manner, and
  3. PATCH version when you make backwards compatible bug fixes.

Adding a type declaration file is clearly no bug fix, so it is clearly not #3. The key here is, that if you add a type declaration file, all the code consuming the API will not break, because the actual js code will not change. Therefore there aren't any incompatible API changes which is another word for backwards compatibility.

This means, if you add a type declaration file, increase the minor version number.