Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Document .js.flow files #3609

Closed
mvolkmann opened this issue Mar 29, 2017 · 15 comments
Closed

Document .js.flow files #3609

mvolkmann opened this issue Mar 29, 2017 · 15 comments
Labels
declarations Issues with library definitions or .js.flow features flow.org Needs docs

Comments

@mvolkmann
Copy link
Contributor

The old documentation described how you could omit types in a file called foo.js and declare the types in a file called foo.js.flow that is located in the same directory. I can't find that in the new documentation. Is that still a supported way to specify types?

@samwgoldman
Copy link
Member

Yes, this is still supported.

@samwgoldman samwgoldman changed the title name.js.flow files supported? Document .js.flow files Mar 29, 2017
@mvolkmann
Copy link
Contributor Author

@mvolkmann
Copy link
Contributor Author

I've tried really hard to get a simple example of this to work and can't get it to detect a simple error where I pass a string for parameter that must be a number. Are you sure .js.flow are really working in the latest version of Flow? Here is my example:

math.js

function double(n) {
  return n * 2;
}

exports.double = double;

math.js.flow

//function double(n: number): number {} // doesn't work
declare export function double(n: number): number; // doesn't work

demo.js

// @flow
const math = require('./math');
console.log(math.double('bad')); // Flow should flag this, but doesn't

When I run flow in this directory, it says No errors!.

@njgraf512
Copy link

I'm also not observing any enforcement by .js.flow files. Same sort of situation as @mvolkmann. Any help would be appreciated.

@AndersDJohnson
Copy link

Very much would like this documented as well. Could inhibit adoption if we don't document this as it's one way to convince a team to transition to Flow without touching the JavaScript source.

@shantp
Copy link

shantp commented Dec 1, 2017

Having the same issue after using flow-copy-files. Also duplicated @mvolkmann's example and get no errors.

EDIT: The above example works if //@flow is added to the .js.flow file. flow-copy-source output does not work though.

@aleclarson
Copy link

aleclarson commented Dec 26, 2017

Using Flow 0.59.0, I can't figure out how to use .js.flow with a CommonJS export:

index.js.flow

declare export class Foo<T> {
  bar(value: T): T;
}

index.js

class Foo {
  bar(value) {
    return value
  }
}

module.exports = Foo

I've also tried adding module.exports = (require('./index'): typeof Foo) to index.js.flow.

@brenmcnamara
Copy link

What I ended up doing was taking a Facebook open source project Draft JS (which auto-generates their .js.flow files) to figure out how they are formatted. If you clone and build the project and look in the "lib" directory, you'll see that the .js.flow files are just the raw js files with the flow syntax in them. I think flow just sees a .flow extension for a file corresponding to the one you add and it just type checks against that.

@LoganBarnett
Copy link

@mvolkmann I believe math.js still needs the // @flow header for the entire thing to type check, otherwise it treats imports from the file as any which Flow ignores entirely.

@LoganBarnett
Copy link

Assuming that's the error, I normally use this linter rule to catch misses like that.

@dperetti
Copy link

dperetti commented Apr 9, 2018

What's the status of this as of today (0.69) ?
I'm just figuring out that the .flow files I have in my vendor libs are not taken in account at all. 🧐

@TrySound
Copy link
Contributor

TrySound commented Apr 9, 2018

@dperetti
Copy link

dperetti commented Apr 9, 2018

You the issue is most vendors don't ship their .flow files into /dist ? Looks like it could be the reason, indeed !

@TrySound
Copy link
Contributor

TrySound commented Apr 9, 2018

@dperetti Sorry, what? Everything works fine with .flow in the projects.

@dperetti
Copy link

dperetti commented Apr 9, 2018

Doh! Found a culprit in my .flowconfig. Sorry !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
declarations Issues with library definitions or .js.flow features flow.org Needs docs
Projects
None yet
Development

Successfully merging a pull request may close this issue.