Search code examples
javascriptflowtype

Same line flow suppress comment for imports


Is there any way to have a suppress comment in Flow that is in the same line as an import?

import Foo from '.bar'
=> throws module not found

// $FlowFixMe
import Foo from '.bar'
=> no error

Ideal:

import Foo from '.bar' // $FlowFixMe
=> cleaner code

Solution

  • You can ignore all ".bar" extension errors by adding mapper in ".flowconfig" file first and then mock.

    [options]
     module.name_mapper.extension='bar' -> '<PROJECT_ROOT>/flow/BarMock.js.flow'
    

    project root path -> flow path -> BarMock.js.flow -> file create

     // @flow
      declare export default "your bar type"