mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2026-10-04 14:57:10 +00:00
Merge pull request #17415 from fengb/bluebird-props
Unwrap Bluebird.props() via generics
This commit is contained in:
@@ -576,7 +576,6 @@ barProm = fooArrProm.spread<Bar>((one: Foo, two: Bar, twotwo: Foo) => {
|
||||
//TODO fix collection inference
|
||||
|
||||
barArrProm = fooProm.all<Bar>();
|
||||
objProm = fooProm.props();
|
||||
fooInspectionPromise = fooProm.reflect();
|
||||
barProm = fooProm.any<Bar>();
|
||||
barArrProm = fooProm.some<Bar>(num);
|
||||
@@ -584,6 +583,17 @@ barProm = fooProm.race<Bar>();
|
||||
|
||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
|
||||
var propsValue: { num: number, str: string };
|
||||
Promise.resolve({ num: 1, str: Promise.resolve('a') }).props().then(val => { propsValue = val });
|
||||
Promise.props({ num: 1, str: Promise.resolve('a') }).then(val => { propsValue = val });
|
||||
Promise.props(Promise.props({ num: 1, str: Promise.resolve('a') })).then(val => { propsValue = val });
|
||||
|
||||
var propsMapValue: Map<number, string>;
|
||||
Promise.resolve(new Map<number, Promise<string>>()).props().then(val => { propsMapValue = val });
|
||||
Promise.props(new Map<number, Promise<string>>()).then(val => { propsMapValue = val });
|
||||
|
||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
|
||||
Promise.all([fooProm, barProm]).then(result => {
|
||||
result[0].foo();
|
||||
result[1].bar();
|
||||
|
||||
Vendored
+9
-5
@@ -620,8 +620,8 @@ declare class Bluebird<R> implements PromiseLike<R>, Bluebird.Inspection<R> {
|
||||
/**
|
||||
* Same as calling `Promise.props(thisPromise)`. With the exception that if this promise is bound to a value, the returned promise is bound to that value too.
|
||||
*/
|
||||
// TODO how to model instance.props()?
|
||||
props(): Bluebird<Object>;
|
||||
props<K, V>(this: PromiseLike<Map<K, Bluebird.Thenable<V> | V>>): Bluebird<Map<K, V>>;
|
||||
props<T>(this: PromiseLike<Bluebird.ResolvableProps<T>>): Bluebird<T>;
|
||||
|
||||
/**
|
||||
* Same as calling `Promise.any(thisPromise)`. With the exception that if this promise is bound to a value, the returned promise is bound to that value too.
|
||||
@@ -806,11 +806,13 @@ declare class Bluebird<R> implements PromiseLike<R>, Bluebird.Inspection<R> {
|
||||
*
|
||||
* *The original object is not modified.*
|
||||
*/
|
||||
// TODO verify this is correct
|
||||
// trusted promise for object
|
||||
static props(object: Bluebird<Object>): Bluebird<Object>;
|
||||
static props<K, V>(map: PromiseLike<Map<K, PromiseLike<V> | V>>): Bluebird<Map<K, V>>;
|
||||
static props<T>(object: PromiseLike<Bluebird.ResolvableProps<T>>): Bluebird<T>;
|
||||
// map
|
||||
static props<K, V>(map: Map<K, PromiseLike<V> | V>): Bluebird<Map<K, V>>;
|
||||
// object
|
||||
static props(object: Object): Bluebird<Object>;
|
||||
static props<T>(object: Bluebird.ResolvableProps<T>): Bluebird<T>;
|
||||
|
||||
/**
|
||||
* Like `Promise.some()`, with 1 as `count`. However, if the promise fulfills, the fulfillment value is not an array of 1 but the value directly.
|
||||
@@ -1074,6 +1076,8 @@ declare namespace Bluebird {
|
||||
/** @deprecated Use PromiseLike<T> directly. */
|
||||
export type Thenable<T> = PromiseLike<T>;
|
||||
|
||||
export type ResolvableProps<T> = object & { [K in keyof T]: PromiseLike<T[K]> | T[K] };
|
||||
|
||||
export interface Resolver<R> {
|
||||
/**
|
||||
* Returns a reference to the controlled promise that can be passed to clients.
|
||||
|
||||
Reference in New Issue
Block a user