Flow: "could not resolve name" for webpack variable injected by the DefinePlugin

Created on 20 Feb 2016  路  5Comments  路  Source: facebook/flow

Flow is warning me about a variable that it cannot resolve:

identifier __VERSION__ Could not resolve name

module.exports = {
  __VERSION__,
  -----------
  ...
}

__VERSION__ is a "free variable" injected by webpack's DefinePlugin:

http://webpack.github.io/docs/list-of-plugins.html#defineplugin

new webpack.DefinePlugin({
  __VERSION__: 'v1.0.0',
})

Is there a way to let Flow know about this variable? Is there a way to tie Flow's config with webpack's config so that it knows about these free variables?

Most helpful comment

Using flow declarations, you can just define them:

declare var __VERSION__:string;

Then flow will typecheck correctly

All 5 comments

Using flow declarations, you can just define them:

declare var __VERSION__:string;

Then flow will typecheck correctly

thank you!

Thanks, @leonardfactory!

Thanks @leonardfactory!

For anybody else who finds this via Google:

You can declare global variables without breaking any other tool that parses your file by using Flow's comment type syntax.

For example we can define the global chrome without breaking Firefox's linting rule requirements for submitting extensions to the Mozilla addons page.

/*::
declare var chrome;
*/
Was this page helpful?
0 / 5 - 0 ratings

Related issues

ghost picture ghost  路  3Comments

Beingbook picture Beingbook  路  3Comments

tp picture tp  路  3Comments

mjj2000 picture mjj2000  路  3Comments

bennoleslie picture bennoleslie  路  3Comments