4

I have a simple Nodejs Typescript project that imports some JavaScript libraries via their TypeScript definition files. ie:

import * as zmq from 'zmq'
const sock = zmq.socket("push");

When I compile this, the result is:

"use strict";
exports.__esModule = true;
var zmq = require("zmq");
var sock = zmq.socket("push");
//# sourceMappingURL=index.js.map

Which looks good, except should the line:

var zmq = require("zmq");

should be the Node JavaScript module for zmq, ie:

var zmq = require("../node_modules/zeromq");

How do I make the compiler do this substitution?

My config is a follows:

{
  "compilerOptions": {
    "declaration": true,
    "module": "commonjs",
    "moduleResolution": "node",
    "noImplicitAny": true,
    "outDir": "./lib",
    "preserveConstEnums": true,
    "removeComments": true,
    "sourceMap": true,
    "typeRoots": [
      "./node_modules/@types"
    ]
  },
  "include": [
    "node_modules/@types/**/*.d.ts",
    "src/**/*"
  ],
  "exclude": [
    "node_modules",
    "**/*-spec.ts",
    "!node_modules/@types/**/*.d.ts"
  ]
}

And zmq is installed as follows:

npm install zeromq --save
npm install @types/zmq --save

Any advice would be great - thanks.

EDIT:

Ok so the issue could be because zeromq is the latest name of the zeromq library I wish to use, but the typings is still called zmq. So it seems that when the compiling it performed the compiler cannot determine zmq should map to zeromq (and why would it).

So would there be a way around this, short of @types/zmq being renamed?

2
  • Just try import mo = require("zmq"); instead of your existing import * as zmq from 'zmq' Commented Jun 19, 2017 at 6:41
  • @DavidR thanks, but dont think that would help - see my edit. Commented Jun 19, 2017 at 7:19

1 Answer 1

1

So would there be a way around this, short of @types/zmq being renamed?

add types.d.ts file with this content:

declare module "zeromq" {
  export * from "zmq"
}
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks that was the snippet I was after.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.