Document .js.flow files
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?
Yes, this is still supported.
Can you comment on this? http://stackoverflow.com/questions/43082488/flow-declaration-files-getting-started#
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!.
I'm also not observing any enforcement by .js.flow files. Same sort of situation as @mvolkmann. Any help would be appreciated.
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.
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.
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.
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.
@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.
Assuming that's the error, I normally use this linter rule to catch misses like that.
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. 🧐
@dperetti https://github.com/renatorib/react-powerplug/blob/master/package.json#L15
You the issue is most vendors don't ship their .flow files into /dist ? Looks like it could be the reason, indeed !
@dperetti Sorry, what? Everything works fine with .flow in the projects.
Doh! Found a culprit in my .flowconfig. Sorry !