I have a NodeJS + ExpressJS which I am migrating to Typescript. I am using a Node module "Formidable" for which I am trying to create a typescript definition. However, I'm not able to import the module elements into Typescript code due to an error:
Here;s the module definition:
/// <reference path="../Main.d.ts" />
declare module "formidable" {
export class Formidable {
constructor();
IncomingForm() : Form;
}
export class Form{
encoding : String;
uploadDir : String;
keepExtensions : Boolean;
type : String;
parse(String, Function) : void;
}
}
Here's the file "Upload.ts" that imports the module
import fs = require('fs');
import path = require('path');
import formidableModule = require('formidable');
var formidable = new formidableModule.Formidable();
Here's "Upload.js" created by the Typescript compiler
var fs = require('fs');
var path = require('path');
var formidableModule = require('formidable');
var formidable = new formidableModule.Formidable();
Here's the error
C:\Users\Me\WebstormProjects\Core\lib\Upload.js:5
var formidable = new formidableModule.Formidable();
^
TypeError: undefined is not a function
at Object.<anonymous> (C:\Users\Anjan\WebstormProjects\Core\lib\Upload.js:5:18)
at Module._compile (module.js:456:26)
at Object.Module._extensions..js (module.js:474:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
at Module.require (module.js:364:17)
at require (module.js:380:17)
at Object.<anonymous> (C:\Users\Anjan\WebstormProjects\Core\app.js:9:20)
at Module._compile (module.js:456:26)
at Object.Module._extensions..js (module.js:474:10)
Process finished with exit code 8