Exploring the possibilities with an electron application developed in typescript. The main focus is on finding the appropriate approach for importing an external module.
Here is my typescript configuration:
{
"compilerOptions": {
"target": "es6",
"module": "commonjs",
"noImplicitAny": false,
"sourceMap": true,
"removeComments": false,
"outDir": "../build"
},
"exclude": [
"node_modules",
"typings/browser.d.ts",
"typings/browser"
]
}
I have divided my code into 2 classes, each residing in its own file.
class person {
private job: job;
public setJob(name: string) {
this.job = new job(name);
}
}
class job {
private name: string;
constructor(name : string) {
var externalTool = require('external-tool');
//Perform actions using the external tool.
}
}
In addition to this, there is a TypeScript file dedicated to the external tool:
declare module ExternalTool {
interface Something {
doSomethingWithName(name:string): string;
}
}
declare module "external-tool" {
export = ExternalTool;
}
The 'require' function references 'https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/node/node.d.ts'
Presently, the 'externalTool' variable is of type 'any'. How can I instruct Typescript to recognize it as the correct type? Switching from require to "import externalTool = require('external-tool')" results in the person class losing recognition of the job class.
What would be the most effective approach in this scenario?