Avoid having types in files where annotation is missingJS-0489
It is not recommended to use flow type imports, aliases, and annotations in files missing a flow file declaration or @flow
annotation. It can be fixed by using @flow
annotation if the file has flow types instead, use @noflow
annotation.
By default, Flow monitors all flow files. It is required to add the flow annotation i.e // @flow
. Without this, Flow will simply ignore the file. Flow gathers all the files with this flag and uses the type information available from them to ensure consistency and error-free programming.
So if a file is having flow types, annotations, aliases and imports in it but no // @flow
annotation before any code in a JavaScript file, those types wont do anything as flow will ignore the file.
Alternatively, developers can use flow check --all
or add a property all=true
in the .flowconfig
file to tell flow to type-check all files.
[options]
all=true
Bad Practice
const x: number = 42;
type FooType = number;
import type A from "a"
export type {A} from "a"
function t<T>(): T{}
Recommended
// @flow
const x: number = 42;
/* @flow weak */
type FooType = number;
/* @noflow */
type FooType = number;
/* @noflow */
import type A from "a"
/* @noflow */
import {type A} from "a"
/* @noflow */
export type {A} from "a"
// an unrelated comment
// @flow
export type {A} from "a"
// @flow
function t<T>(): T{}