BVB Source Codes

prettier Show promise.js Source code

Return Download prettier: download promise.js Source code - Download prettier Source code - Type:.js
  1. /**
  2.  * @flow
  3.  */
  4.  
  5. //////////////////////////////////////////////////
  6. // == Promise constructor resolve() function == //
  7. //////////////////////////////////////////////////
  8.  
  9. // Promise constructor resolve(T) -> then(T)
  10. new Promise(function(resolve, reject) {
  11.   resolve(0);
  12. }).then(function(num) {
  13.   var a: number = num;
  14.  
  15.   // TODO: The error message that results from this is almost useless
  16.   var b: string = num; // Error: number ~> string
  17. });
  18.  
  19. // Promise constructor with arrow function resolve(T) -> then(T)
  20. new Promise((resolve, reject) => resolve(0))
  21.   .then(function(num) {
  22.     var a: number = num;
  23.  
  24.     // TODO: The error message that results from this is almost useless
  25.     var b: string = num; // Error: number ~> string
  26.   });
  27.  
  28. // Promise constructor resolve(Promise<T>) -> then(T)
  29. new Promise(function(resolve, reject) {
  30.   resolve(new Promise(function(resolve, reject) {
  31.     resolve(0);
  32.   }));
  33. }).then(function(num) {
  34.   var a: number = num;
  35.   var b: string = num; // Error: number ~> string
  36. });
  37.  
  38. // Promise constructor resolve(Promise<Promise<T>>) -> then(T)
  39. new Promise(function(resolve, reject) {
  40.   resolve(new Promise(function(resolve, reject) {
  41.     resolve(new Promise(function(resolve, reject) {
  42.       resolve(0);
  43.     }));
  44.   }));
  45. }).then(function(num) {
  46.   var a: number = num;
  47.   var b: string = num; // Error: number ~> string
  48. });
  49.  
  50. // Promise constructor resolve(T); resolve(U); -> then(T|U)
  51. new Promise(function(resolve, reject) {
  52.   if (Math.random()) {
  53.     resolve(42);
  54.   } else {
  55.     resolve('str');
  56.   }
  57. }).then(function(numOrStr) {
  58.   if (typeof numOrStr === 'string') {
  59.     var a: string = numOrStr;
  60.   } else {
  61.     var b: number = numOrStr;
  62.   }
  63.   var c: string = numOrStr; // Error: number|string -> string
  64. });
  65.  
  66. /////////////////////////////////////////////////
  67. // == Promise constructor reject() function == //
  68. /////////////////////////////////////////////////
  69.  
  70. // TODO: Promise constructor reject(T) -> catch(T)
  71. new Promise(function(resolve, reject) {
  72.   reject(0);
  73. }).catch(function(num) {
  74.   var a: number = num;
  75.  
  76.   // TODO
  77.   var b: string = num; // Error: number ~> string
  78. });
  79.  
  80. // TODO: Promise constructor reject(Promise<T>) ~> catch(Promise<T>)
  81. new Promise(function(resolve, reject) {
  82.   reject(new Promise(function(resolve, reject) {
  83.     reject(0);
  84.   }));
  85. }).catch(function(num) {
  86.   var a: Promise<number> = num;
  87.  
  88.   // TODO
  89.   var b: number = num; // Error: Promise<Number> ~> number
  90. });
  91.  
  92. // TODO: Promise constructor reject(T); reject(U); -> then(T|U)
  93. new Promise(function(resolve, reject) {
  94.   if (Math.random()) {
  95.     reject(42);
  96.   } else {
  97.     reject('str');
  98.   }
  99. }).catch(function(numOrStr) {
  100.   if (typeof numOrStr === 'string') {
  101.     var a: string = numOrStr;
  102.   } else {
  103.     var b: number = numOrStr;
  104.   }
  105.  
  106.   // TODO
  107.   var c: string = numOrStr; // Error: number|string -> string
  108. });
  109.  
  110. /////////////////////////////
  111. // == Promise.resolve() == //
  112. /////////////////////////////
  113.  
  114. // Promise.resolve(T) -> then(T)
  115. Promise.resolve(0).then(function(num) {
  116.   var a: number = num;
  117.   var b: string = num; // Error: number ~> string
  118. });
  119.  
  120. // Promise.resolve(Promise<T>) -> then(T)
  121. Promise.resolve(Promise.resolve(0)).then(function(num) {
  122.   var a: number = num;
  123.   var b: string = num; // Error: number ~> string
  124. });
  125.  
  126. // Promise.resolve(Promise<Promise<T>>) -> then(T)
  127. Promise.resolve(Promise.resolve(Promise.resolve(0))).then(function(num) {
  128.   var a: number = num;
  129.   var b: string = num; // Error: number ~> string
  130. });
  131.  
  132. ////////////////////////////
  133. // == Promise.reject() == //
  134. ////////////////////////////
  135.  
  136. // TODO: Promise.reject(T) -> catch(T)
  137. Promise.reject(0).catch(function(num) {
  138.   var a: number = num;
  139.  
  140.   // TODO
  141.   var b: string = num; // Error: number ~> string
  142. });
  143.  
  144. // TODO: Promise.reject(Promise<T>) -> catch(Promise<T>)
  145. Promise.reject(Promise.resolve(0)).then(function(num) {
  146.   var a: Promise<number> = num;
  147.  
  148.   // TODO
  149.   var b: number = num; // Error: Promise<number> ~> number
  150. });
  151.  
  152. //////////////////////////////////
  153. // == Promise.prototype.then == //
  154. //////////////////////////////////
  155.  
  156. // resolvedPromise.then():T -> then(T)
  157. Promise.resolve(0)
  158.   .then(function(num) { return 'asdf'; })
  159.   .then(function(str) {
  160.     var a: string = str;
  161.     var b: number = str; // Error: string ~> number
  162.   });
  163.  
  164. // resolvedPromise.then():Promise<T> -> then(T)
  165. Promise.resolve(0)
  166.   .then(function(num) { return Promise.resolve('asdf'); })
  167.   .then(function(str) {
  168.     var a: string = str;
  169.     var b: number = str; // Error: string ~> number
  170.   });
  171.  
  172. // resolvedPromise.then():Promise<Promise<T>> -> then(T)
  173. Promise.resolve(0)
  174.   .then(function(num) { return Promise.resolve(Promise.resolve('asdf')); })
  175.   .then(function(str) {
  176.     var a: string = str;
  177.     var b: number = str; // Error: string ~> number
  178.   });
  179.  
  180. // TODO: resolvedPromise.then(<throw(T)>) -> catch(T)
  181. Promise.resolve(0)
  182.   .then(function(num) {
  183.     throw 'str';
  184.   })
  185.   .catch(function(str) {
  186.     var a: string = str;
  187.  
  188.     // TODO
  189.     var b: number = str; // Error: string ~> number
  190.   });
  191.  
  192. ///////////////////////////////////
  193. // == Promise.prototype.catch == //
  194. ///////////////////////////////////
  195.  
  196. // rejectedPromise.catch():U -> then(U)
  197. Promise.reject(0)
  198.   .catch(function(num) { return 'asdf'; })
  199.   .then(function(str) {
  200.     var a: string = str;
  201.     var b: number = str; // Error: string ~> number
  202.   });
  203.  
  204. // rejectedPromise.catch():Promise<U> -> then(U)
  205. Promise.reject(0)
  206.   .catch(function(num) { return Promise.resolve('asdf'); })
  207.   .then(function(str) {
  208.     var a: string = str;
  209.     var b: number = str; // Error: string ~> number
  210.   });
  211.  
  212. // rejectedPromise.catch():Promise<Promise<U>> -> then(U)
  213. Promise.reject(0)
  214.   .catch(function(num) { return Promise.resolve(Promise.resolve('asdf')); })
  215.   .then(function(str) {
  216.     var a: string = str;
  217.     var b: number = str; // Error: string ~> number
  218.   });
  219.  
  220. // resolvedPromise<T> -> catch() -> then():?T
  221. Promise.resolve(0)
  222.   .catch(function(err) {})
  223.   .then(function(num) {
  224.     var a: ?number = num;
  225.     var b: string = num; // Error: string ~> number
  226.   });
  227.  
downloadpromise.js Source code - Download prettier Source code
Related Source Codes/Software:
storybook - 2017-06-07
ionicons - The premium icon font for Ionic ... 2017-06-07
AsyncDisplayKit - Smooth asynchronous user interfaces for iOS apps. ... 2017-06-07
lottie-android - Render After Effects animations natively on Androi... 2017-06-07
parse-server - Parse-compatible API server module for Node/Expres... 2017-06-07
inferno - An extremely fast, React-like JavaScript library f... 2017-06-08
guetzli - Perceptual JPEG encoder 2017-06-08
cs-video-courses - List of Computer Science courses with video lectur... 2017-06-08
interviews - Everything you need to know to get the job. 2017-06-08
prepack - Prepack is a partial evaluator for JavaScript. Pre... 2017-06-08
CRYENGINE - CRYENGINE is a powerful real-time game development... 2017-06-11
postal - 2017-06-11
reactide - Reactide is the first dedicated IDE for React web ... 2017-06-11
rkt - rkt is a pod-native container engine for Linux. It... 2017-06-11
uWebSockets - Tiny WebSockets https://for... 2017-06-11
realworld - TodoMVC for the RealWorld - Exemplary fullstack Me... 2017-06-11
goreplay - GoReplay is an open-source tool for capturing and ... 2017-06-10
pyenv - Simple Python version management 2017-06-10
redux-saga - An alternative side effect model for Redux apps ... 2017-06-10
angular-starter - 2017-06-10

 Back to top