[Work in progress] Flowtype typings


Hello there!


I’ve started to work on Flow types for Meteor. I know about these TypeScript ones, but there’s one thing… These are shallow. Let’s take this code:

import {Mongo} from 'meteor/mongo';

const Collection = new Mongo.Collection('collection');

const transform = doc => ({_id: doc._id, fields: Object.keys(doc).length});
const docs = Collection.find({}, {transform}).fetch();

What is the type of notes? Well, according to current TS types, it’s the collection type (inferred or whatever). My goal is to provide complete types. Current state allows you to do this:

(docs: {|_id: string, fields: number|}[]);

And of course throws an error here:

docs.map(doc => doc.other);

Yep, it’s correctly typed!


Main goal is to type whole Meteor core packages, namely this directory and (finally!) make a pull request to flow-typed.


Current version provides complete types for two medium-sized projects (you can see, which part of API are these two using, as the rest is not typed yet).

How can I try it?

Simply go here and clone it into your flow-typed directory.

How can I help?

  1. Drop it in your project.
  2. Fix something and/or type missing parts.
  3. Make a pull request.

It’s that simple!

Update 2018-01-10

Few people asked me, how do I work with Flow and Meteor. Here’s a .flowconfig working with both 1.5 and 1.6:


module.name_mapper='^\/\(.*\)$' -> '<PROJECT_ROOT>/\1'
module.name_mapper='^meteor\/\(.*\):\(.*\)$' -> '<PROJECT_ROOT>/.meteor/local/build/programs/server/packages/\1_\2'
module.name_mapper='^meteor\/\(.*\):\(.*\)$' -> '<PROJECT_ROOT>/.meteor/local/build/programs/web.browser/packages/\1_\2'
module.name_mapper='^meteor\/\(.*\)$' -> '<PROJECT_ROOT>/.meteor/local/build/programs/server/packages/\1'
module.name_mapper='^meteor\/\(.*\)$' -> '<PROJECT_ROOT>/.meteor/local/build/programs/web.browser/packages/\1'

We ignore .json files from Meteor sources (.npm is a directory for bundled npm modules), because some of them contains comments.

Using flowtype in Meteor packages/applications

Love the initiative. I do not use flow type yet, but I do understand its advantages and I do believe that the price you pay (extra code) is worth it in the end.


Yes, it really is! And to be honest it’s not that big. The only price I see is the time needed for getting on with Flow (or static typing at all if you are not familiar with it).

Also, there’s no much more code as most types are inferred. That’s why it’s better (and, in a way, easier) to provide high quality typing for libraries.


@radekmie what’s the status with this ? Do you plan on continuing it ? I think this will mark an important evolution to enterprise JS within Meteor.


@diaconutheodor Yes, I’m still continuing it. Right now I’m introducing Flow on another project, and it turned out to be BFS and not DFS implementation cycle… Long story short, it will be continued but I’m focusing on making it complete one by one rather than opening all and having none finished.


Update: Three projects typed so far! Kind of milestone :rocket:


Nice! I believe you should share a bit of your knowledge in a Medium blogpost, like what are the challenges, what are the best patterns, what are some pitfalls. I have less experience in this regard, but definitely I see Flow as something that will be used in the future.

I am planning to create flow-typed for Grapher and RedisOplog, not sure yet how to nicely integrate them in a project… Maybe you can do it for uniforms first so I have some inspiration :smiley: :smiley:

I’ve been using VSCode with Flow Type integration it works just amazing. I love JS flexibility but I was missing the Java/C# consistency, now we have both, no doubt in my mind JS is gonna surpass any other language eventually.


Blog post? Well, it’s an idea. A good one actually.

About typings for Grapher and RedisOplog - I could help you with that. At the beginning, at least. About the uniforms - I’m on it for a long while (I’ve checked my git stash - for almost 6 months now), but I haven’t got time to finish it… New year’s resolution? Who knows!

I’m not very into statically vs dynamically typed languages (C, Lua and JS here), but it’s definitely easier to introduce someone into a typed project, even without a proper documentation.


Hi @radekmie
Thanks for taking the initiative. I’ve added a PR to your repo covering another part of Meteor API.