mirror of
https://github.com/FlipsideCrypto/DefinitelyTyped.git
synced 2026-02-06 10:56:53 +00:00
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.
55 lines
1.4 KiB
TypeScript
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')
|
|
);
|
|
}
|