Q“noConflict()”的TypeScript定義(d.t)

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


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

我現在正在做一個項目,在那里我使用Q庫進行打字稿的承諾。

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

最新版本的Q有方法Q.noConflict()。我用的是。d。來自定義式存儲庫的ts文件。

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

輸入不支持Q.noConflict()。為了支持這種方法,我花了幾個小時來重新編寫,但是沒有成功。

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.

當然,我不希望得到所有的代碼,但是從那些已經寫了一些。d的人那里得到一些提示是很好的。ts文件。

1 个解决方案

#1


4  

Use typeof Q as the return type:

使用類型Q作為返回類型:

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

注意!

本站翻译的文章,版权归属于本站,未经许可禁止转摘,转摘请注明本文地址:https://www.itdaan.com/blog/2015/06/24/342569baa0f77594e873382eba7719f2.html



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