beaugunderson/ip-address

Typescript consumers are required to install @types/jsbn

stevenhair opened this issue · 3 comments

Since Address4 and Address6 both have public methods that use the BigInteger type from jsbn, any typescript users with a reasonable configuration will be required to explicitly install @types/jsbn, otherwise they will receive the following error:

node_modules/ip-address/dist/lib/ipv4.d.ts:2:28 - error TS7016: Could not find a declaration file for module 'jsbn'. '/Users/shair/dev/projects/auth/hs-webauth-api/node_modules/ip-address/node_modules/jsbn/index.js' implicitly has an 'any' type.
  Try `npm i --save-dev @types/jsbn` if it exists or add a new declaration (.d.ts) file containing `declare module 'jsbn';`

2 import { BigInteger } from 'jsbn';
                             ~~~~~~
node_modules/ip-address/dist/lib/ipv6.d.ts:3:28 - error TS7016: Could not find a declaration file for module 'jsbn'. '/Users/shair/dev/projects/auth/hs-webauth-api/node_modules/ip-address/node_modules/jsbn/index.js' implicitly has an 'any' type.
  Try `npm i --save-dev @types/jsbn` if it exists or add a new declaration (.d.ts) file containing `declare module 'jsbn';`

3 import { BigInteger } from 'jsbn';
                             ~~~~~~

Found 2 error(s).

Installing @types/jsbn works, but consumers shouldn't be required to explicitly install dependencies of dependencies. Unfortunately, I'm not aware of an easy solution to the problem. As far as I know, there are two ways that this can be solved (and they both have downsides):

  1. Add @types/jsbn to the dependencies: This is not the best solution, since it requires everyone (not just Typescript users) to install it and it's not easily removed with npm prune --production
  2. Include a copy of the BigInteger interface in ip-address and use that type in Address4 and Address6: I'm not familiar with BigInteger, but it could have significant maintenance costs.

As a workaround, you can enable the skipLibCheck option in your tsconfig.json's compilerOptions.

Ah, I was unaware of this compiler option. Thanks!

I think skipLibCheck is the right thing here 👍