BVB Source Codes

prettier Show variance.js Source code

Return Download prettier: download variance.js Source code - Download prettier Source code - Type:.js
  1. /* @flow */
  2.  
  3. class A {}
  4. class B extends A {}
  5. class C extends B {}
  6.  
  7. declare var a: A;
  8. declare var b: B;
  9. declare var c: C;
  10.  
  11. class Base {
  12.   x: B;
  13.   +pos: B;
  14.   -neg: B;
  15.   get get(): B { return this.x };
  16.   set set(value: B): void { this.x = value };
  17.   get getset(): B { return this.x };
  18.   set getset(value: B): void { this.x = value };
  19. }
  20.  
  21. (class extends Base {
  22.   // error: getter incompatible with read/write property
  23.   get x(): B { return b }
  24. });
  25.  
  26. (class extends Base {
  27.   // error: setter incompatible with read/write property
  28.   set x(value: B): void {}
  29. });
  30.  
  31. (class extends Base {
  32.   // ok: get/set co/contra with read/write property, resp.
  33.   get x(): C { return c }
  34.   set x(value: A): void {}
  35. });
  36.  
  37. (class extends Base {
  38.   // error: setter incompatible with read-only property
  39.   set pos(value: B): void {}
  40. });
  41.  
  42. (class extends Base {
  43.   // ok: getter covariant with read-only property
  44.   get pos(): C { return c }
  45. });
  46.  
  47. (class extends Base {
  48.   // error: getter incompatible with write-only property
  49.   get neg(): B { return b }
  50. });
  51.  
  52. (class extends Base {
  53.   // ok: setter contravariant with write-only property
  54.   set neg(value: A): void {}
  55. });
  56.  
  57. (class extends Base {
  58.   // ok: read/write covariant with getter
  59.   get: C;
  60. });
  61.  
  62. (class extends Base {
  63.   // ok: read/write contravariant with setter
  64.   set: A;
  65. });
  66.  
  67. (class extends Base {
  68.   // ok: read/write invariant with get/set
  69.   getset: B;
  70. });
  71.  
downloadvariance.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