BVB Source Codes

prettier Show class.js Source code

Return Download prettier: download class.js Source code - Download prettier Source code - Type:.js
  1. /**
  2.  * @flow
  3.  */
  4.  
  5. var z: number = 123;
  6.  
  7. class Foo {
  8.   get goodGetterNoAnnotation() { return 4; }
  9.   get goodGetterWithAnnotation(): number { return 4; }
  10.  
  11.   set goodSetterNoAnnotation(x) { z = x; }
  12.   set goodSetterWithAnnotation(x: number) { z = x; }
  13.  
  14.   get propWithMatchingGetterAndSetter(): number { return 4; }
  15.   set propWithMatchingGetterAndSetter(x: number) { }
  16.  
  17.   // The getter and setter need not have the same type - no error
  18.   get propWithSubtypingGetterAndSetter(): ?number { return 4; }
  19.   set propWithSubtypingGetterAndSetter(x: number) { }
  20.  
  21.   // The getter and setter need not have the same type - no error
  22.   set propWithSubtypingGetterAndSetterReordered(x: number) { }
  23.   get propWithSubtypingGetterAndSetterReordered(): ?number { return 4; }
  24.  
  25.   get propWithMismatchingGetterAndSetter(): number { return 4; }
  26.   set propWithMismatchingGetterAndSetter(x: string) { } // doesn't match getter (OK)
  27.  
  28.   propOverriddenWithGetter: number;
  29.   get propOverriddenWithGetter() { return "hello"; }
  30.  
  31.   propOverriddenWithSetter: number;
  32.   set propOverriddenWithSetter(x: string) { }
  33.  
  34.   set [z](x: string) {}
  35.   get [z](): string { return string; }
  36. };
  37.  
  38. var foo = new Foo();
  39.  
  40. // Test getting properties with getters
  41. var testGetterNoError1: number = foo.goodGetterNoAnnotation;
  42. var testGetterNoError2: number = foo.goodGetterWithAnnotation;
  43.  
  44. var testGetterWithError1: string = foo.goodGetterNoAnnotation; // Error number ~> string
  45. var testGetterWithError2: string = foo.goodGetterWithAnnotation; // Error number ~> string
  46.  
  47. // Test setting properties with getters
  48. foo.goodSetterNoAnnotation = 123;
  49. foo.goodSetterWithAnnotation = 123;
  50.  
  51. // TODO: Why does no annotation mean no error?
  52. foo.goodSetterNoAnnotation = "hello"; // Error string ~> number
  53. foo.goodSetterWithAnnotation = "hello"; // Error string ~> number
  54.  
  55. var testSubtypingGetterAndSetter: number = foo.propWithSubtypingGetterAndSetter; // Error ?number ~> number
  56.  
  57. var testPropOverridenWithGetter: number = foo.propOverriddenWithGetter; // Error string ~> number
  58. foo.propOverriddenWithSetter = 123; // Error number ~> string
  59.  
downloadclass.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