Professor-Redwood-Team / Professor-Redwood

Pokemon Go Discord Bot
MIT License
34 stars 21 forks source link

Adding typehints? #32

Closed fmoo closed 6 years ago

fmoo commented 7 years ago

I have a local branch that adds flow support to the project, annotates a few modules, and includes third-party annotations for discord.js, mocha, and mysql.

I can clean it up a bit and submit a PR, but wanted to ask if this was something you would be interested in having first.

Happy to discuss merits/drawbacks here or on discord. lmk.

mralanlee commented 7 years ago

@fmoo would we have apply the changes to everything else? I'm not against this idea, I like it a lot actually, and I think we should also add JSDoc to methods and libraries too since most editors will support that natively as well.

fmoo commented 7 years ago

@kniteshift - So, flow's gradual typing only requires you to add type annotations to module export boundaries for files you've added a @flow comment to.

Modules without @flow anywhere are not checked, and are treated as "any" objects by files that do until more context is inferred. Flow support is totally optional for third-party libraries.

The most disruptive thing(s) about supporting flow is:

mralanlee commented 7 years ago

@fmoo ah got it, therefore modules that do not pull flow in will not have any effect or issues.

I personally would like to use something like this as well as some of the babel presets for async functions (some of my pull requests have API calls or DB queries) where I've been using Promises but I think we could benefit from having async functions to make the code look much cleaner. This is probably another subject of it's own.

I'm definitely for giving flow a try, would definitely make maintenance lot easier in the long term.

fmoo commented 7 years ago

modules that do not pull flow in will not have any effect or issues

Yeah, modules that don't have /* @flow */ in them will not be checked for type errors. There is no restriction on which modules can be imported by flow or non-flow code. Local code without the @flow tag is treated the same as untyped, third-party code.

It's best to add it to all your local files though, since it will help catch bugs.

It's also worth re-iterating that flow is an offline typechecker - you run it during development and before landing your changes, like you would your unittests - the annotations are completely stripped by babel, so there is little to no runtime penalty.