Flow allows you to use the following syntax to import types:
// SomeClass.js
export default class SomeClass {}
// SomeFile.js
import type SomeClass from './SomeClass';
What's the benefit of using import type
instead of import
? Does it tell Flow more information and let it perform better static analysis?
For the specific case of classes, it is either example will work. The key thing is that it breaks down like this:
import type ... from
imports a Flow typeimport ... from
imports a standard JS value, and the type of that value.A JS class produces a value, but Flowtype also interprets a class declaration as a type declaration, so it is both.
So where is import type
important?
export type Foo = { prop: number };
for instance can only be important with import type { Foo } from ...
, since there is no value named Foo
import type ...
only influences typechecking, and not runtime behavior, you can import a type without actually requiring the imported file to execute, avoiding potential cycles.