Flow: import type allows not existent types, despite untyped-type-import being enabled

Created on 5 Feb 2019  路  10Comments  路  Source: facebook/flow

Flow allows to import missing types and this already gave me a few bugs.

// module.js
// @flow
export type Value = 1;
// index.js
// @flow
import type { Values } from './module.js';

Flow version: 0.91.0

Expected behavior

Flow should error on missing type

Actual behavior

No errors

bug

Most helpful comment

In 2015, untyped-type-import didn't exist, so I believe that was (and still is) expected behavior. The bug is that untyped-type-import doesn't catch this.

All 10 comments

Weird...I get

Error ---------------------------------------------------------------------------------------------------- index.js:2:15

Cannot import `Values` because there is no `Values` export in `./module.js`. Did you mean `Value`?

   2| import type { Values } from './module.js';
                    ^^^^^^



Found 1 error

Tried both v0.91 and v0.92.

Are you sure both files had @flow? Was there anything weird in your .flowconfig?

My directory:

$ ls -la
total 20
drwxr-xr-x.  2 glevi users   55 Feb  4 16:19 .
drwxr-xr-x. 23 glevi users 4096 Feb  4 16:18 ..
-rw-r--r--.  1 glevi users   58 Feb  4 16:18 .flowconfig
-rw-r--r--.  1 glevi users   52 Feb  4 16:19 index.js
-rw-r--r--.  1 glevi users   33 Feb  4 16:19 module.js
$ cat .flowconfig
[ignore]

[include]

[libs]

[lints]

[options]

[strict]
$ cat index.js
// @flow
import type { Values } from './module.js';
[glevi@devbig023 foo]$ cat module.js
// @flow

export type Value = 1;

@gabelevi Sorry, I didn't reproduced this properly. The error came from relay artefacts. Try this
module.js

// @flow

export type Value = number;

const node/*: any*/ = (function(){})();
module.exports = node;

index.js

// @flow
import type { Values } from './module.js';

.flowconfig

[ignore]

[include]

[libs]

[lints]
untyped-type-import=error

[options]

[strict]

untyped-type-import doesn't work here and probably it's not related to the problem. Here module.exports any hides defined types for some reason.

I chatted with @TrySound on our Discord and provided this example to explain why I believe we should not error in this situation by default. Basically, classes are both values and types, which makes this not quite as straightforward as it might be otherwise.

However, I believe that the untyped-type-import lint should catch this. I'm going to retitle this to make it a bit clearer.

Hah, this problem exists since 2015
https://github.com/facebook/flow/issues/721

In 2015, untyped-type-import didn't exist, so I believe that was (and still is) expected behavior. The bug is that untyped-type-import doesn't catch this.

Hi @nmote Is this still on your radar?

Sorry if I gave the wrong impression here. I'm not currently working on this, I was just helping with diagnosis.

Hi @gabelevi Could you take a look at this if you have a time?

Was this page helpful?
0 / 5 - 0 ratings