Guest User

Untitled

a guest
Aug 20th, 2018
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.35 KB | None | 0 0
  1. interface PromiseClass<A, P extends PromiseLike<A>> {
  2. new(callback: (resolve: (value?: A | P) => void, reject: (reason?: any) => void) => void): P;
  3. }
  4.  
  5. const bar: PromiseClass<number, Bluebird<number>> = Bluebird; // OK
  6.  
  7. interface Options<A, P extends PromiseLike<A>, C extends PromiseClass<A, P>> {
  8. promise?: C;
  9. }
  10.  
  11. function foo<A, P extends PromiseLike<A>, C extends PromiseClass<A, P>>(options: Options<A, P, C>) { /* empty */ }
  12.  
  13. foo({ promise: Bluebird.resolve(3) });
  14.  
  15. foo<number, Bluebird<number>, PromiseClass<number, Bluebird<number>>>({ promise: Bluebird.resolve(3) });
  16.  
  17. foo<number, Bluebird<number>, PromiseClass<number, Bluebird<number>>>({ promise: Bluebird.resolve(3) });
  18.  
  19. declare class PromisePool<
  20. A, // the type of value returned by the source
  21. P extends PromiseLike<A>, // the type of Promise returned by the source
  22. P2 extends PromiseLike<A>, // the type of Promise specified in `options`
  23. C extends PromisePool.PromiseClass<A, P2> // a helper class
  24. > {
  25. constructor(
  26. source: IterableIterator<P> | P | (() => (P | undefined)) | A,
  27. concurrency: number,
  28. options?: PromisePool.Options<A, P2, C>
  29. );
  30.  
  31. promise(): P2;
  32. start(): P2;
  33. }
  34.  
  35. declare namespace PromisePool {
  36. interface PromiseClass<A, P extends PromiseLike<A>> {
  37. new(callback: (resolve: (value?: A | P) => void, reject: (reason?: any) => void) => void): P;
  38. }
  39.  
  40. interface Options<A, P extends PromiseLike<A>, C extends PromiseClass<A, P>> {
  41. promise?: C;
  42. }
  43. }
  44.  
  45. declare class PromisePool<
  46. A, // the type of value returned by the source
  47. P extends PromiseLike<A>, // the type of Promise returned by the source
  48. P2 extends PromiseLike<A>, // the type of Promise specified in `options`
  49. C extends PromisePool.PromiseClass<A, P2> // a helper class
  50. > {
  51. constructor(
  52. source: IterableIterator<P> | P | (() => (P | undefined)) | A,
  53. concurrency: number,
  54. options?: PromisePool.Options<A, P2, C>
  55. );
  56.  
  57. promise(): P2;
  58. start(): P2;
  59. }
  60.  
  61. declare namespace PromisePool {
  62. interface PromiseClass<A, P extends PromiseLike<A>> {
  63. new(callback: (resolve: (value?: A | P) => void, reject: (reason?: any) => void) => void): P;
  64. }
  65.  
  66. interface Options<A, P extends PromiseLike<A>, C extends PromiseClass<A, P>> {
  67. promise?: C;
  68. }
  69. }
Add Comment
Please, Sign In to add comment