BVB Source Codes

prettier Show rest.js Source code

Return Download prettier: download rest.js Source code - Download prettier Source code - Type:.js
  1. /* regression tests */
  2.  
  3. function rest_array<T>(...xs: Array<T>): T { // Ok, arrays can be rest params
  4.   return xs[0];
  5. }
  6.  
  7. function rest_tuple<T>(...xs: [T]): T { // Ok, tuples can be rest params
  8.   return xs[0];
  9. }
  10.  
  11. function rest_ro_array<T>(...xs: $ReadOnlyArray<T>): T { // Ok
  12.   return xs[0];
  13. }
  14.  
  15. function rest_any(...xs: any): any { // Ok, any can be a rest param
  16.   return xs[0];
  17. }
  18.  
  19. function rest_t<U, T: Array<U>>(...xs: T): U { // Ok, bounded targ can be rest
  20.   return xs[0];
  21. }
  22.  
  23. // These are ok bounds for the rest param
  24. function unbound_rest_t<T>(...xs: T): void {}
  25. function mixed_rest_t<T: mixed>(...xs: T): void {}
  26. function array_rest_t<T: Array<mixed>>(...xs: T): void {}
  27. function roarray_rest_t<T: $ReadOnlyArray<mixed>>(...xs: T): void {}
  28. function iterable_rest_t<T: Iterable<mixed>>(...xs: T): void {}
  29. function empty_rest_t<T: empty>(...xs: T): void {}
  30. function bounds_on_bounds<T>() {
  31.   return function<U: T>(...xs: T): void {}
  32. }
  33.  
  34. // These are bad bounds for the rest param
  35. function bad_unbound_rest_t<T>(...xs: T): T {
  36.   return xs.pop(); // Error - no bound on T
  37. }
  38. function string_rest_t<T: string>(...xs: T): void {} // Error - rest param can't be a string
  39. function empty_rest_t<T: empty>(...xs: T): void {} // Error - rest param can't be empty
  40.  
  41. type Rest = Array<string>;
  42. function rest_alias(...xs: Rest): void {} // Ok
  43.  
  44. function rest_union(...xs: [1,2] | Array<number>): number { // OK
  45.   return xs[0];
  46. }
  47.  
  48. function rest_intersection(...xs: { x: number } & [1,2]): number { // OK
  49.   return xs[0] + xs.x;
  50. }
  51.  
  52. function empty_rest<T:Array<mixed>>(...xs: T): T { return xs; }
  53. (empty_rest(): empty); // Error Array ~> empty
  54.  
  55. function return_rest_param<Args:Array<mixed>>(
  56.   f: (...args: Args) => void,
  57. ): (...args: Args) => number {
  58.   return function(...args) {
  59.     return args; // Error: Array ~> number
  60.   }
  61. }
  62.  
  63. function requires_first_param(x: number, ...rest: Array<number>): void {}
  64. requires_first_param(); // Error: missing first arg
  65.  
downloadrest.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