Static Type Checking
Maintaining large projects
Chapter 3: Static Type Checking
Probably you have noticed it's a lot easier to develop new projects than support old ones. That's because of complexity that tends to grow fast as we add new features to the program.
So, you might start breaking up your code into smaller modules, then add testingand maybe add some linting. But what about the way those modules interact with each other? Wouldn't be great if we can define a contract that sets clear boundaries of what to except and enforce it? And that's where static type checking comes in.
Also, Meteor has some plans to move on with TypeScript and is encouraging developers to help out with the conversion to TypeScript. But we'll be using FlowType which is supported by the ecmascript package. Flow is much easier to pick up and can be incrementally adopted. Don't worry if you can use one you won't face much trouble using the other.
meteor npm i --save-dev flow-bin eslint-plugin-flowtype
This is an opionated configuration.
.flowconfig file inside your project root:
[options] # Absolute path support: # e.g. "/collections/todos" module.name_mapper='^\/\(.*\)$' -> '<PROJECT_ROOT>/\1' # Meteor none core package support # e.g. "meteor/kadira:flow-router" module.name_mapper='^meteor\/\(.*\):\(.*\)$' -> '<PROJECT_ROOT>/.meteor/local/build/programs/server/packages/\1_\2' # Meteor core package support # e.g. "meteor/meteor" module.name_mapper='^meteor\/\(.*\)$' -> '<PROJECT_ROOT>/.meteor/local/build/programs/server/packages/\1' # Fallback for Meteor core client package # e.g. "meteor/meteor" module.name_mapper='^meteor\/\(.*\)$' -> '<PROJECT_ROOT>/.meteor/local/build/programs/web.browser/packages/\1' # Structural mapping module.name_mapper='^modules\/\(.*\)$' -> '<PROJECT_ROOT>/src/modules/\1' module.name_mapper='^core\/\(.*\)$' -> '<PROJECT_ROOT>/src/modules/core/\1' module.name_mapper='^ui\/\(.*\)$' -> '<PROJECT_ROOT>/src/client/\1' [ignore] # Ignore the `.meteor/local` packages that aren't important .*/.meteor/local/build/programs/server/app/.* .*/.meteor/local/build/programs/server/assets/.* .*/.meteor/local/build/programs/server/npm/.* .*/.meteor/local/build/programs/server/node_modules/.* .*/.meteor/local/build/programs/web.browser/app/.* .*/.meteor/local/build/main.js .*/.meteor/packages/.*
If you're using vscode there're few adjustments to be made. And that's it, enjoy!