Reputation: 75
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?
Upvotes: 4
Views: 408
Reputation: 11600
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"
}
Upvotes: 1