Flow: Errors suppressed on react Component when imported by a lib

Created on 22 Mar 2018  路  6Comments  路  Source: facebook/flow

Here is a minimal repository with the bug: https://github.com/ckknight/flow-libs-bug

On line 6 of src/App.js, this.props.nonexistent() is called, which _should_ be a type error.

By having the following lines in .flowconfig:

[libs]
flowlib/

and a file within that folder:

// @flow

import { Component } from 'react';

declare module 'foo' {
  declare module.exports: any;
}

Regardless of whether foo is referenced anywhere else, the import { Component } from 'react'; line causes flow to view Component as any within unrelated code.

Most helpful comment

@sibelius sure it _should_ be import type { Component } from 'react'. Instead, my errors were completely swallowed with zero indication that there was a problem. That's the real issue.

All 6 comments

In #5678, which refers to the same issue as this one, it was explained that imports outside of module declarations are not supported, so I think this issue can be closed now.

it should be import type { Component } from 'react' instead

and you could also use React$Component in some cases

@sibelius Sorry, I'm unclear as to whether imports outside of module declarations are supported or not?

@sibelius sure it _should_ be import type { Component } from 'react'. Instead, my errors were completely swallowed with zero indication that there was a problem. That's the real issue.

Closing in favour of the referenced issues

Was this page helpful?
0 / 5 - 0 ratings

Related issues

iamchenxin picture iamchenxin  路  3Comments

philikon picture philikon  路  3Comments

bennoleslie picture bennoleslie  路  3Comments

funtaps picture funtaps  路  3Comments

ctrlplusb picture ctrlplusb  路  3Comments