Skip to content

Flow to Vanilla JavaScript — Numio

Strips Flow type annotations to produce plain JavaScript using Babel's flow-strip-types plugin. Type-only imports and type aliases are removed, and the page then formats the result with Prettier.

You are removing Flow from a project and want the plain JavaScript first, before deciding whether to move to TypeScript.

Flow

JavaScript

When to use it

  • You are removing Flow from a project and want the plain JavaScript first, before deciding whether to move to TypeScript.
  • You need to paste a Flow-typed snippet into a place that only accepts standard JavaScript, such as a browser console or a codepen.

How to use

  1. Paste Flow-annotated code (with or without the // @flow header) into the Flow panel.
  2. The code is posted to /api/flow-to-javascript, where recast parses it with the Flow parser and Babel removes the types.
  3. Copy the JavaScript from the output panel.

Flow

// @flow
import type { Store } from './store';
import { createStore } from './store';

type State = { count: number };

export function first<T>(items: Array<T>): ?T {
  return items.length ? items[0] : null;
}

const store: Store<State> = createStore(({ count: 0 }: State));

export default store;

JavaScript

import { createStore } from "./store"

export function first(items) {
  return items.length ? items[0] : null
}

const store = createStore({
  count: 0,
})

export default store

Details and limitations

The page sends your input to a server route (/api/flow-to-javascript) for conversion; it is not processed only in the browser. Next.js API routes accept request bodies up to 1 MB by default.

Only types are removed. Modern syntax such as JSX, ?? or class fields is not transpiled.

The result is reformatted with Prettier (double quotes, no semicolons), so the original style is not kept, and a type cast such as ({ count: 0 }: State) loses its extra parentheses.

A // @flow comment attached to a removed type declaration is removed with it.

FAQ

Does it keep JSX?

Yes. JSX is parsed and passed through unchanged, so you still need a JSX transform to run the result.

What happens to import type statements?

They are removed entirely. Regular imports stay as they are.

Does the output need Flow or Babel to run?

No Flow is needed. If the input uses JSX or new syntax, your runtime or bundler must still support it.

Specifications and references