BVB Source Codes

prettier Show overload.js Source code

Return Download prettier: download overload.js Source code - Download prettier Source code - Type:.js
  1. /**
  2.  * tests of overload selection
  3.  *
  4.  * @flow
  5.  */
  6.  
  7. var x1: number = "".match(0)[0];
  8. var x2: number = "".match(/pattern/)[0];
  9. var x3: string = "".replace(/pattern/,"...");
  10. var x4: number = "".split(/pattern/)[0];
  11.  
  12. declare class C {
  13.     foo(x:number): number;
  14.     foo(x:string): string;
  15.  
  16.     bar(x: { a: number }): number;
  17.     bar(x: { a: string }): string;
  18. }
  19.  
  20. var a = new C();
  21.  
  22. a.foo(0); // ok
  23. a.foo("hey"); // ok
  24. a.foo(true); // error, function cannot be called on intersection type
  25.  
  26. a.bar({ a: 0 }); // ok
  27. a.bar({ a: "hey" }); // ok
  28. a.bar({ a: true }); // error, function cannot be called on intersection type
  29.  
  30. declare var x: { a: boolean; } & { b: string };
  31.  
  32. a.bar(x); // error with nested intersection info (outer for bar, inner for x)
  33.  
  34. /********** tests **************
  35. interface Dummy<T> {
  36.     dumb(foo: (x:number) => number):number;
  37.     dumb(foo: (x:string) => string):string;
  38.  
  39.     dumber<U>(bar: (x:T) => Array<U>):U;
  40.     dumber<U>(bar: (x:T) => U):Array<U>;
  41. }
  42.  
  43. function foo(x:string):string { return x; }
  44. var y:number = new Dummy().dumb(foo);
  45.  
  46. function bar1(x:number):Array<string> { return []; }
  47. var z1:number = new Dummy().dumber(bar1);
  48.  
  49. function bar2(x:number):string { return "..."; }
  50. var z2:Array<string> = new Dummy().dumber(bar2);
  51. */
  52.  
downloadoverload.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