Search code examples
flowtypeflow-typed

How do I tell Flow that there will be a class on window without explicitly specifying its type?


I want to incorporate the Google Maps JS library into a Flow-typed project. Since there aren't any remotely complete Flow externs for the library, I'd like to tell Flow to accept whatever methods and constants I call from the class as Function and any, respectively. I know that the best answer would be to write a complete extern for GMaps and post it on Github, but I've got deadlines to meet. Using flow-typed is also an option to generate stubs, but that only seems to work on npm packages. What would be the best way to tackle this?


Solution

  • If you want to completely skip checks, you can simply declare:

    declare var google: any;

    Which will allow you to do whatever you want to google:

    google.maps.Map();
    google();
    google.maps.Map.call();
    

    Or if you wanted to at least ensure you always call google.maps.something and never google by itself:

    declare var google: { maps: Object };