BVB Source Codes

prettier Show apply.js Source code

Return Download prettier: download apply.js Source code - Download prettier Source code - Type:.js
  1. function test(a: string, b: number): number {
  2.   return this.length; // expect []/"" this
  3. }
  4.  
  5. // tuples flow correctly into params
  6. test.apply("", ["", 0]);
  7.  
  8. // wrong this is an error
  9. test.apply(0, ["", 0]); // error: lookup `length` on Number
  10.  
  11. // not enough arguments is an error
  12. test.apply("", [""]); // error: void ~> number
  13.  
  14. // mistyped arguments is an error
  15. test.apply("", ["", ""]); // error: string ~> number (2nd arg)
  16. test.apply("", [0, 0]); // error: number ~> string (1st arg)
  17.  
  18. // resolve args array from tvar
  19. function f(args) { test.apply("", args) }
  20. f(["", 0]); // OK
  21. f(["", ""]); // error: string ~> number (2nd arg)
  22. f([0, 0]); // error: number ~> string (1st arg)
  23.  
  24. // expect array
  25. test.apply("", "not array"); // error: expect array of args
  26.  
  27. // expect 4 errors:
  28. // - lookup length on Number (because 0 is used as `this`)
  29. // - 123 is not a string
  30. // - 'foo' is not a number
  31. // - return type (number) is not void
  32. (test.call.apply(test, [0, 123, 'foo']): void);
  33.  
  34. // expect 2 errors:
  35. // - lookup length on number (0 is used as `this`)
  36. // - 123 is not a string
  37. (test.bind.apply(test, [0, 123]): (b: number) => number);
  38.  
  39. // args are optional
  40. function test2(): number { return 0; }
  41. (test2.apply(): number);
  42. (test2.apply(""): number);
  43.  
  44. // callable objects
  45. function test3(x: { (a: string, b: string): void }) {
  46.   x.apply(x, ['foo', 'bar']); // ok
  47.   x.apply(x, ['foo', 123]); // error, number !~> string
  48. }
  49.  
downloadapply.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