DefinitelyTyped/types/bluebird-global/bluebird-global-tests.ts
d-ph 3cf3939630 [bluebird-global] Miscellaneous improvements
1. Bring copy&pasted code from std lib back to sync.
2. Come up with a plan to remove the copy&paste from std lib
3. Add an information that due to how these typings work,
   users can't cast instances of global Promise to Bluebird
   promise. Also, mention a walk-around if that's needed.
2018-08-26 15:20:29 +01:00

55 lines
1.4 KiB
TypeScript

function testSomeStaticMethods() {
Promise.config({});
Promise.delay(100).then(() => {});
Promise.all([]).finally(() => {});
}
function testFunctionReturningPromise() {
function functionReturningPromise(): Promise<string> {
return new Promise<string>((resolve, reject, onCancel) => {
if (onCancel) {
onCancel(() => {
console.log("onCancel cleanup");
});
}
resolve("lorem ipsum");
})
.then((value) => {
return value + " dolor";
});
}
functionReturningPromise()
.then((value) => {
console.log("then callback: " + value);
})
.finally(() => {
console.log("finally callback");
});
}
function testPromiseRejection() {
new Promise<string>((resolve, reject) => {
reject(new Error("problem occurred"));
})
.catch((error) => {
return "recovered from error";
})
.then((value) => {
return value.toUpperCase();
});
}
function testGithubTicket28081Regression() {
Promise.resolve([3]).map((n: number) => true);
}
import Bluebird = require("bluebird");
function testTheWalkaroundForCastingGlobalPromiseToBluebirdPromise() {
const bluebirdString: Bluebird<string> = Bluebird.resolve(
new Promise<string>(() => 'Lorem ipsum')
);
}