我正在嘗試爲要用於將文件上載到服務器的NodeJS強大模塊創建Typescript定義。但是這會引發錯誤。打字稿編譯器不編譯語句「import formidable = require('formidable');」到其等效的JavaScript。我需要知道這個強大的定義是否正確。試圖爲NodeJS模塊創建Typescript定義
下面是其中包含的文件解析代碼upload.ts:
import fs = require('fs');
import path = require('path');
import formidable = require('formidable');
var formidable = new formidable.Formidable();
這裏是它是由打字稿編譯器創建的upload.js:
var fs = require('fs');
var path = require('path');
var formidable = new formidable.Formidable();
的打字稿編譯器不創建要求聲明爲強大的模塊。這需要修復。
這裏的打字稿定義文件:
/// <reference path="../Main.d.ts" />
declare module "formidable" {
export interface Formidable {
IncomingForm(): Formidable;
}
}
這是一個非常完整的答案! – Fenton
謝謝瑞恩!這是一個非常有用的答案。但是,由於另一個錯誤,我的代碼沒有解決。你可以看看這個問題嗎? http://stackoverflow.com/questions/20603247/unable-to-import-nodejs-module-into-typescript-code – EternallyCurious