flow icon indicating copy to clipboard operation
flow copied to clipboard

export = in declarations file

Open fdecampredon opened this issue 12 years ago • 5 comments

I try to use bluebird. The definition file is like that.


declare module "bluebird" {

  declare class Promise<R>  {
    constructor(callback: (resolve : (result: R) => void, reject: (error: any) => void) => void): void;
    then<U>(onFulfill?: (value: R) => Promise<U> | U, onReject?: (error: any) => Promise<U> | U): Promise<U>;
    catch<U>(onRejected?: (error: any) => Promise<U> | U ): Promise<U>;
    static resolve<T>(thenable?: Promise<T> | T): Promise<T>;
    static reject(error: any): Promise<any>;
    static all<T>(promises: Array<Promise<T>>): Promise<Array<T>>;
    static race<T>(promises: Array<Promise<T>>): Promise<T>;
  }
}

The problem is that I have no way to declare that 'bluebird' is 'Promise', with typescript I would do :

export = Promise;

is there a way to declare such behavior ?

fdecampredon avatar Nov 20 '14 10:11 fdecampredon

Not yet, will fix.

avikchaudhuri avatar Nov 20 '14 10:11 avikchaudhuri

+1.

Would be nice to be able to export not only class, but function and var too:

declare module 'some-module' {
   declare var typeOfModule : string;
}

ptmt avatar Nov 26 '14 13:11 ptmt

What's the workaround for this? I am trying to use the var ClassNames = require('classnames') ; Not sure how to declar the interface for this.

ransanjeev avatar May 10 '15 19:05 ransanjeev

Generally you should be able to use the "special" identifier exports to declare your default exports. However, it seems there is an issue (#457) with polymorphic default exports which will prevent a default exported bluebird Promise class from correctly type checking.

See #455 for an example of the exports declaration.

samwgoldman avatar May 20 '15 23:05 samwgoldman

ok, #457 is fixed, so this should be possible in master, and when 0.13 is released.

mroch avatar Jun 18 '15 00:06 mroch