Flow Remove Types is a fast, zero-configuration tool for removing Flow type annotations from JavaScript files. It provides both command-line and programmatic APIs, serving as a lightweight alternative to Babel for type stripping with minimal dependencies and maximum performance.
npm install flow-remove-typesconst flowRemoveTypes = require('flow-remove-types');For require hook:
require('flow-remove-types/register');For Jest integration:
// jest.config.js
module.exports = {
transform: {
"^.+\\.js(?:\\.flow)?$": "flow-remove-types/jest"
}
};const flowRemoveTypes = require('flow-remove-types');
const fs = require('fs');
// Read Flow-typed source
const input = fs.readFileSync('input.js', 'utf8');
// Remove types
const result = flowRemoveTypes(input, {
pretty: false, // Keep whitespace for exact positioning
all: false // Only process files with @flow pragma
});
// Get transformed code
const output = result.toString();
fs.writeFileSync('output.js', output);
// Generate source map if needed
const sourceMap = result.generateMap();Flow Remove Types is built around several key components:
Core transformation function for removing Flow type annotations from JavaScript source code with configurable options.
function flowRemoveTypes(source, options);Fast CLI tool for transforming Flow files with support for single files, directories, and advanced options like source maps.
flow-remove-types [options] [sources]
flow-node [options] [script.js] [arguments]Automatic compilation hooks and transformers for seamless development workflow integration.
require('flow-remove-types/register')(options);interface TransformResult {
toString(): string;
generateMap(): SourceMap;
}
interface TransformOptions {
all?: boolean;
pretty?: boolean;
ignoreUninitializedFields?: boolean;
removeEmptyImports?: boolean;
}
interface SourceMap {
version: number;
sources: string[];
names: string[];
mappings: string;
file?: string;
sourcesContent?: string[];
}