Registry / type-stubs / babel-plugin-reflow

babel-plugin-reflow

JSON →
library0.5.7jsnpmunverified

Babel plugin to transpile Flow type annotations to TypeScript, with a CLI wrapper for batch conversion. Current stable version 0.5.7 (latest). Development appears slow but active with periodic releases. Key differentiators: focuses on pretty output via Prettier, handles comments well, proven on real projects (27k and 41k LOC). Compared to alternatives like flow-to-ts or babel-plugin-flow-to-typescript, Reflow offers a CLI and better output formatting. Supports base types, generics, utility types, nullable types, optional chaining, nullish coalescing, and class decorator replacement. Limitation: empty Flow object types become `object` not `{}` since v0.5.

npm install babel-plugin-reflow
INSTALL
IMPORT
SIG · BABEL-PLUGIN-REFLO
B
babel-plugin-reflow
type-stubsjavascriptv0.5.7
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

default
import reflow from 'babel-plugin-reflow'
const reflow = require('babel-plugin-reflow')
Plugin is exported as default export. CommonJS require works but TypeScript users should use default import.
ReflowError
import { ReflowError } from 'babel-plugin-reflow'
import ReflowError from 'babel-plugin-reflow'
ReflowError is a named export, not default.
plugin
// .babelrc { "plugins": ["babel-plugin-reflow"] }
{ "plugins": ["reflow"] }
Plugin name in Babel config is the full package name.

Demonstrates CLI usage to transpile a directory and programmatic usage with Babel.

// Install: npm install --save-dev babel-plugin-reflow // Run CLI on src directory, replace .js with .ts in-place: // npx reflow --replace src/ // Or with dry run: // npx reflow -d src/ // Programmatic usage: const reflow = require('babel-plugin-reflow'); const babel = require('@babel/core'); const code = ` // @flow function greet(name: string): string { return 'Hello, ' + name; } `; const result = babel.transformSync(code, { plugins: [reflow], filename: 'input.js', }); console.log(result.code); // Output: // function greet(name: string): string { // return 'Hello, ' + name; // }
reflow --version
Debug
Known issues
breakingEmpty Flow object types `{}` are transformed to `object` instead of `{}` since v0.5.0.
fix
Manually replace `object` with `{}` in generated code if `{}` semantics required.
affects: >=0.5.0
deprecatedThe `--exclude-dirs` option is deprecated in favor of `--exclude-patterns`.
fix
Use `--exclude-patterns '**/node_modules/**'` instead.
affects: >=0.4.0
gotchaFlow's `mixed` type is transformed to `unknown` in TypeScript; this may not be type-safe for codebases relying on dynamic access.
fix
Audit uses of `mixed` and add type guards or assertions as needed.
affects: >=0.1.0
gotchaFunction type inference may differ: Flow's exact object types may become less precise.
fix
Review generated types for exact object semantics and add `Readonly` or `as const` as needed.
affects: >=0.1.0
warningPlugin does not handle `$ReadOnlyArray`, `$ReadOnly`, `$Exact` utilities; they may cause errors.
fix
Manually replace with TypeScript equivalents or suppress errors.
affects: >=0.1.0
Errors
Common errors & fixes
Error: Could not find plugin 'babel-plugin-reflow'
Package not installed or not in node_modules.
fix
Run `npm install --save-dev babel-plugin-reflow` or `yarn add --dev babel-plugin-reflow`.
SyntaxError: Unexpected token (1:10) (While processing: ...)
File contains Flow syntax but Babel is not configured to parse Flow first.
fix
Add `@babel/preset-flow` to your Babel presets before the Reflow plugin.
TypeScript error: Type 'object' is not assignable to type '{}'
Reflow v0.5+ converts empty object `{}` to `object` which is not compatible.
fix
Either adjust TypeScript config to allow `object` or manually replace `object` with `{}`.
Error: Unknown option 'exclude-dirs'
Using deprecated CLI option.
fix
Replace `--exclude-dirs` with `--exclude-patterns` and update the pattern syntax.
Upgrade
Version history
0.5.7latest on npm
Audit
Dependencies
@babel/corerequiredBabel plugin runs on Babel core
prettierrequiredUsed for code formatting output
chokidaroptionalUsed in CLI for file watching
Agent activity
34 hits · last 30 days
node
30
OpenAI (training)
1
Resources
babel-plugin-reflow — npm install babel-plugin-reflow · libregistry