Flow: React ComponentType not checked correctly in the presence of a library definition importing it.

Created on 4 Jun 2018  ยท  3Comments  ยท  Source: facebook/flow

Flow version

0.73.0

Unexpected behavior

The following program type checks with no errors, but should have a missing prop error

// @flow

import React, { type ComponentType } from 'react';

const X: ComponentType<{ foo: string }> = () => null;

export const test = <X />;

when I have a library definition containing the line

import type { Component, ComponentType } from 'react';

... in my flow-typed directory.

  • Replacing ComponentType with React$ComponentType in the failing example causes the error to be reported correctly.

  • Removing the import and using React$ComponentType in the libdef causes the failing example to be reported correctly (in my case, along with a few hundred new - seemingly valid - issues in my code base)

Expected

Either of

  • Flow reports the missing prop error in the presence of this import
  • Flow reports the library defintion as invalid instead of silenty failing.
declarations

Most helpful comment

@fishythefish I'm not sure it is possible to reproduce this on try flow. I can only repro this with a .flowconfig and with library file present in the flow-typed folder. To repro you can create three files

./index.js

// @flow

import React, { type ComponentType } from 'react';
const X: ComponentType<{ foo: string }> = () => null;
const test = <X />;

./flow-typed/test.js

import type { Component, ComponentType } from 'react';

.flowconfig

[libs]
./flow-typed/.*

The error will be silenced as described on flow 0.73.0. Removing the line in the library defintion will correctly result in the error

Error โ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆ index.js:7:15

Cannot create X element because property foo is missing in props [1] but exists in object type [2].

      4โ”‚
 [2]  5โ”‚ const X: ComponentType<{ foo: string }> = () => null;
      6โ”‚
 [1]  7โ”‚ const test = <X />;
      8โ”‚


All 3 comments

Can you supply a minimal example? I can't reproduce your issue on Try Flow. Are you saying the line in the library definition is silencing this error?

@fishythefish I'm not sure it is possible to reproduce this on try flow. I can only repro this with a .flowconfig and with library file present in the flow-typed folder. To repro you can create three files

./index.js

// @flow

import React, { type ComponentType } from 'react';
const X: ComponentType<{ foo: string }> = () => null;
const test = <X />;

./flow-typed/test.js

import type { Component, ComponentType } from 'react';

.flowconfig

[libs]
./flow-typed/.*

The error will be silenced as described on flow 0.73.0. Removing the line in the library defintion will correctly result in the error

Error โ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆโ”ˆ index.js:7:15

Cannot create X element because property foo is missing in props [1] but exists in object type [2].

      4โ”‚
 [2]  5โ”‚ const X: ComponentType<{ foo: string }> = () => null;
      6โ”‚
 [1]  7โ”‚ const test = <X />;
      8โ”‚


I'm also getting this issue, and I've set up a small repro here:

https://github.com/stevenla/flow-module-import-test

Was this page helpful?
0 / 5 - 0 ratings

Related issues

bennoleslie picture bennoleslie  ยท  3Comments

damncabbage picture damncabbage  ยท  3Comments

cubika picture cubika  ยท  3Comments

Beingbook picture Beingbook  ยท  3Comments

jamiebuilds picture jamiebuilds  ยท  3Comments