[英]TypeScript Definition (d.ts) for Q “noConflict()”

I'm currently working an a project where I use the Q Library for promises with TypeScript.


The newest Version of Q has the method Q.noConflict(). For the typing I'm using the .d.ts File from the DefinitelyTyped Repository.


The typing does not support Q.noConflict(). I tried several hours to rewrite the typing to support this method, but with no success.


I would like to use the code Like this:


var myQ = Q.noConflict();

Where myQ is of Type Q. But in the .d.ts Q is a module which has Interfaces as well as functions. That means I can't simply add something like this noConflict(): Q.

myQ的類型為q,但在。d中。ts Q是一個具有接口和功能的模塊。這意味着我不能簡單地添加這樣的noConflict(): Q。

Here is the schema from the definition file (not the whole file but with all relevant parts):


declare function Q(value: T): Q.Promise;

聲明函數Q(值:T): Q.Promise;

declare module Q {
    interface IPromise<T> {
        then<U>(onFulfill?: (value: T) => U | IPromise<U>, onReject?: (error: any) => U | IPromise<U>): IPromise<U>;

    interface Deferred<T> {
        promise: Promise<T>;

    interface Promise<T> {
        get<U>(propertyName: String): Promise<U>;

    export function when(): Promise<void>;

    export function resolve<T>(object: T): Promise<T>;

declare module "q" {
    export = Q;

Of course I don't expect to get the whole code but it would be great the get some hints from people who have already written some .d.ts files.


1 个解决方案



Use typeof Q as the return type:


declare module Q {
    // ...
    export function noConflict(): typeof Q;
    // ...



粤ICP备14056181号  © 2014-2020 ITdaan.com