Last active
          May 11, 2017 21:14 
        
      - 
      
 - 
        
Save mvolkmann/fac4d915b02dcf3b7c6ea7b482f2fdcd to your computer and use it in GitHub Desktop.  
    Flow .js.flow declaration files
  
        
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | const double = require('./math').double; | |
| console.log(double('20')); | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | function double(n) { | |
| return n * 2; | |
| } | |
| exports.double = double; | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | // This didn't work for me. | |
| //function double(n: number): number {} | |
| // This didn't work either. | |
| declare export function double(n: number): number; | |
| // Running "flow" in the directory of these files outputs "No errors!" | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment
  
            
Okay, you'll need to have
// @flowat the top of bothdemo.jsandmath.js.flow. Then you'll seeWithout
// @flowat the top of your files flow will report no errors. It might be nice if it said "0 files checked (you need to add @flow to some files)" but unfortunately it doesn't.You can copy
math.jstemporarily to add@flowat the top so that you can rungen-flow-fileson it. But even if you do that you get an error becausegen-flow-filesonly works on files that have flow type annotations:I think it would be reasonable for flow to infer that
doubletakes and returns a number since it uses multiplication, but unfortunately it doesn't make that inference. So generally for creating.js.flowfiles for source files out of your control that don't have type annotations, you'll be best off writing them by hand.