BVB Source Codes

prettier Show incompatible.js Source code

Return Download prettier: download incompatible.js Source code - Download prettier Source code - Type:.js
  1. /* @flow */
  2.  
  3. var x : {[key: string]: string} = {};
  4. var y : {[key: string]: number} = x; // 2 errors, number !~> string & vice versa
  5. var z : {[key: number]: string} = x; // 2 errors, string !~> number & vice versa
  6.  
  7. var a : {[key: string]: ?string} = {};
  8. var b : {[key: string]: string} = a; // 2 errors (null & undefined)
  9. var c : {[key: string]: ?string} = b; // 2 errors, since c['x'] = null updates b
  10.  
  11. // 2 errors (number !~> string, string !~> number)
  12. function foo0(x: Array<{[key: string]: number}>): Array<{[key: string]: string}> {
  13.   return x;
  14. }
  15.  
  16. // error, fooBar:string !~> number (x's dictionary)
  17. function foo1(
  18.   x: Array<{[key: string]: number}>
  19. ): Array<{[key: string]: number, fooBar: string}> {
  20.   return x;
  21. }
  22.  
  23. function foo2(
  24.   x: Array<{[key: string]: mixed}>
  25. ): Array<{[key: string]: mixed, fooBar: string}> {
  26.   x[0].fooBar = 123; // OK, since number ~> mixed (x elem's dictionary)
  27.   return x; // error: mixed ~> string
  28. }
  29.  
  30. // OK, since we assume dictionaries have every key
  31. function foo3(x: {[key: string]: number}): {foo: number} {
  32.   return x;
  33. }
  34.  
  35. // error: foo can't exist in x
  36. function foo4(x: {[key: string]: number}): {[key: string]: number, foo: string} {
  37.   return x;
  38. }
  39.  
  40. // error, some prop in x could be incompatible (covariance)
  41. function foo5(x: Array<{[key: string]: number}>): Array<{foo: number}> {
  42.   return x;
  43. }
  44.  
  45. // error, some prop in return could be incompatible
  46. function foo6(x: Array<{foo: number}>): Array<{[key: string]: number}> {
  47.   return x;
  48. }
  49.  
  50. function foo7(x: {bar: string, [key: string]: number}) {
  51.   (x.bar: string);
  52. }
  53.  
  54. function foo8(x: {[key: string]: number}) {
  55.   (x.foo: string); // error
  56.   (x.foo: number);
  57. }
  58.  
downloadincompatible.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