2017-02-22 00:59:19 +03:00
|
|
|
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
|
|
|
|
2017-03-22 03:38:28 +03:00
|
|
|
exports[`promise.js 1`] = `
|
2017-04-12 23:41:51 +03:00
|
|
|
/**
|
2016-12-23 22:31:38 +03:00
|
|
|
* Here the definition of Promise<T> is routed to the class Promise
|
|
|
|
* in the user-specified library libs/Promise.js
|
|
|
|
*
|
|
|
|
* In such situations we must desugar async/await primitives
|
|
|
|
* to the shadowed library definition.
|
|
|
|
*
|
|
|
|
* @flow
|
|
|
|
*/
|
|
|
|
|
|
|
|
async function foo(x: boolean): Promise<?{bar: string}> {
|
|
|
|
if (x) {
|
2017-02-22 00:59:19 +03:00
|
|
|
return {bar: 'baz'}; // OK, because of covariant type param
|
2016-12-23 22:31:38 +03:00
|
|
|
} else {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
async function run() {
|
|
|
|
console.log(await foo(true));
|
|
|
|
console.log(await foo(false));
|
|
|
|
}
|
|
|
|
|
|
|
|
run()
|
|
|
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
2016-12-27 21:29:31 +03:00
|
|
|
/**
|
|
|
|
* Here the definition of Promise<T> is routed to the class Promise
|
|
|
|
* in the user-specified library libs/Promise.js
|
|
|
|
*
|
|
|
|
* In such situations we must desugar async/await primitives
|
|
|
|
* to the shadowed library definition.
|
|
|
|
*
|
|
|
|
* @flow
|
|
|
|
*/
|
2017-01-10 05:49:06 +03:00
|
|
|
|
2016-12-27 21:29:31 +03:00
|
|
|
async function foo(x: boolean): Promise<?{ bar: string }> {
|
|
|
|
if (x) {
|
2017-04-12 23:41:51 +03:00
|
|
|
return { bar: "baz" }; // OK, because of covariant type param
|
2016-12-27 21:29:31 +03:00
|
|
|
} else {
|
2016-12-28 05:40:04 +03:00
|
|
|
return null;
|
2016-12-27 21:29:31 +03:00
|
|
|
}
|
|
|
|
}
|
2017-01-10 05:49:06 +03:00
|
|
|
|
2016-12-27 21:29:31 +03:00
|
|
|
async function run() {
|
2016-12-28 05:40:04 +03:00
|
|
|
console.log(await foo(true));
|
|
|
|
console.log(await foo(false));
|
2016-12-27 21:29:31 +03:00
|
|
|
}
|
2017-01-10 05:49:06 +03:00
|
|
|
|
2017-01-11 18:16:38 +03:00
|
|
|
run();
|
2017-04-12 23:41:51 +03:00
|
|
|
|
2016-12-23 22:31:38 +03:00
|
|
|
`;
|