1

This question is very close to my question, and the comments in the linked question are really helpful, but I cannot seem to make a pure "ghost" module.

The code I'm struggling with can be found here I have a file "mariasql.d.ts", and a test file "mariasql-tests.ts". The *.d.ts file exposes a constructor function, that works like so:

var Client = require('mariasql),
c = new Client();

Based on the other SO quesion, the *.d.ts file exports like so:

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;
}

The import code in the test file looks like so:

/// <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 ...

note - the github link will read c:Client.prototype which also did not work.

I feel like I must be misunderstanding something(s) obvious.

0

1 Answer 1

2

What you have is perfectly fine. The only minor fix needed is in your test instead of

var c:Client.prototype = new Client(),

You need to use the interface:

var c: MARIASQL.MariaClient = new Client(),

Or remove it entirely and let the compiler infer it for you ;).

Sign up to request clarification or add additional context in comments.

2 Comments

Also I would prefer mariasql instead of MARIASQL
I just issued a PR, sorry I didn't see this comment in time; I misunderstood the example and assumed caps was the "style".

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.