1
This question是很接近接近我的問題,並且鏈接問題中的註釋非常有幫助,但我似乎無法制作純「鬼」模塊。TypeScript 1.4作爲構造函數公開的CommonJS模塊
我在努力的代碼可以be found here我有一個文件「mariasql.d.ts」和一個測試文件「mariasql-tests.ts」。在* .d.ts文件暴露了一個構造函數,那就像這樣:
var Client = require('mariasql),
c = new Client();
基於其他SO quesion中,* .d.ts文件導出像這樣:
module MARIASQL {
//... edited for brevity
export interface MariaClient {
connect(config:ClientConfig):void;
end():void;
destroy():void;
escape(query:string):string;
query(q:string, placeHolders?:Dictionary, useArray?:boolean):MariaQuery;
query(q:string, placeHolders?:Array<any>, useArray?:boolean):MariaQuery;
query(q:string, useArray?:boolean):MariaQuery;
prepare(query:string): MariaPreparedQuery;
isMariaDB():boolean;
on(signal:string, cb:MariaCallBackError): MariaClient; // signal 'error'
on(signal:string, cb:MariaCallBackObject): MariaClient; // signal 'close'
on(signal:string, cb:MariaCallBackVoid): MariaClient; // signal 'connect'
connected: boolean;
threadId: string;
}
export interface Client {
new():MariaClient;
():MariaClient;
prototype: MariaClient;
}
}
declare module "mariasql" {
var Client:MARIASQL.Client;
export = Client;
}
的在測試文件導入代碼看起來像這樣:
/// <reference path="../node/node-0.10.d.ts" />
/// <reference path="./mariasql.d.ts" />
// Example 1 - SHOW DATABASES
import util = require('util');
import Client = require('mariasql');
var c:Client = new Client(),
inspect = util.inspect;
// edited ...
注 - GitHub的鏈接將讀取c:Client.prototype
這也沒有工作。
我覺得我必須誤解一些明顯的東西。
另外我更喜歡'mariasql'而不是'MARIASQL' – basarat 2015-04-01 23:55:49
我*只是*發佈PR,抱歉我沒有及時看到此評論;我誤解了這個例子,並認爲上限是「風格」。 – Bennett 2015-04-02 00:07:11