BVB Source Codes

prettier Show Arith.js Source code

Return Download prettier: download Arith.js Source code - Download prettier Source code - Type:.js
  1.  
  2. /* @providesModule Arith */
  3.  
  4. function num(x:number) { }
  5.  
  6. function str(x:string) { }
  7.  
  8. function foo() {
  9.   var x = 0;
  10.   var y = "...";
  11.   var z = {};
  12.   num(x+x);
  13.   num(x+y); // error
  14.   str(x+y);
  15.   str(x+x); // error
  16.   str(z+y); // error
  17. }
  18.  
  19. // test MaybeT(NumT)
  20. function bar0(x: ?number, y: number) {
  21.   num(x + y);
  22. }
  23. function bar1(x: number, y: ?number) {
  24.   num(x + y);
  25. }
  26.  
  27. // test OptionalT(NumT)
  28. function bar2(x?: number, y: number) {
  29.   num(x + y);
  30. }
  31. function bar3(x: number, y?: number) {
  32.   num(x + y);
  33. }
  34.  
  35. // test OptionalT(MaybeT(NumT))
  36. function bar4(x?: ?number, y: number) {
  37.   num(x + y);
  38. }
  39. function bar5(x: number, y?: ?number) {
  40.   num(x + y);
  41. }
  42.  
  43. num(null + null); // === 0
  44. num(undefined + undefined); // === NaN
  45.  
  46. num(null + 1); // === 1
  47. num(1 + null); // === 1
  48. num(undefined + 1); // === NaN
  49. num(1 + undefined); // === NaN
  50.  
  51. num(null + true); // === 1
  52. num(true + null); // === 1
  53. num(undefined + true); // === NaN
  54. num(true + undefined); // === NaN
  55.  
  56. str("foo" + true); // error
  57. str(true + "foo"); // error
  58. str("foo" + null); // error
  59. str(null + "foo"); // error
  60. str("foo" + undefined); // error
  61. str(undefined + "foo"); // error
  62.  
  63. let tests = [
  64.   function(x: mixed, y: mixed) {
  65.     (x + y); // error
  66.     (x + 0); // error
  67.     (0 + x); // error
  68.     (x + ""); // error
  69.     ("" + x); // error
  70.     (x + {}); // error
  71.     ({} + x); // error
  72.   },
  73.  
  74.   // when one side is a string or number and the other is invalid, we
  75.   // assume you are expecting a string or number (respectively), rather than
  76.   // erroring twice saying number !~> string and obj !~> string.
  77.   function() {
  78.     ((1 + {}): number); // error: object !~> number
  79.     (({} + 1): number); // error: object !~> number
  80.     (("1" + {}): string); // error: object !~> string
  81.     (({} + "1"): string); // error: object !~> string
  82.   },
  83.  
  84.   function(x: any, y: number, z: string) {
  85.     (x + y: string); // ok
  86.     (y + x: string); // ok
  87.  
  88.     (x + z: empty); // error, string ~> empty
  89.     (z + x: empty); // error, string ~> empty
  90.   },
  91. ];
  92.  
downloadArith.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