Generate flowtype definition files from TypeScript
Last updated 2 years ago by anru .
ISC · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install ts2flow 
SYNC missed versions from official npm registry.


This is a fork of flowgen. For reasons why ts2flow have been forked from flowgen see this commit message.


  1. Add PR to flowgen fixing declare export interface issue
  2. Make ts2flow cli tool for flowgen itself

The state of the converter

It's surprisingly robust and non-lossy as it stands right now, in big part thanks to how similar flow and typescript definition files are. Please see the output in this flow-typed PR for the state of the output.


Install using npm i ts2flow --save

import { compiler } from 'flowgen';

// To compile a d.ts file
const flowdef = compiler.compileDefinitionFile(filename);

// To compile a string
const flowdef = compiler.compileDefinitionString(str);

Recommended second step:

import { beautify } from 'flowgen';

// Make the definition human readable
const readableDef = beautify(generatedFlowdef);


Standard usage (prints result to stdout):

npm i -g ts2flow
ts2flow lodash.d.ts


-o / --output-file: Specifies the filename of the exported file, if not specified stdout will be used

The difficult parts


Namespaces have been a big headache. What it does right now is that it splits any namespace out into prefixed global scope declarations instead. It works OK, but its not pretty and there's some drawbacks to it.

External library imports

Definitions in TS and flow are often quite different, and imported types from other libraries dont usually have a one-to-one mapping. Common cases are React.ReactElement, React.CSSPropsetc. This might require manual processing, or we add a set of hardcoded mutations that handle common cases.

Odd TS conventions

Lodash has been one of the reference libraries i've worked with when creating the converter. The definition is mostly just a series of interfaces with the same name being re-declared over and over again for each function, which doesn't translate to flow at all. There's multiple ways of solving this but I dont have a great solution for it in place yet.


All help is appreciated. Please tweet at me if you want some help getting started, or just want to discuss ideas on how to solve the trickier parts.

Current Tags

  • 2.0.4                                ...           latest (2 years ago)

5 Versions

  • 2.0.4                                ...           2 years ago
  • 2.0.3                                ...           2 years ago
  • 2.0.2                                ...           2 years ago
  • 2.0.1                                ...           2 years ago
  • 2.0.0                                ...           2 years ago
Maintainers (1)
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 0
Dependencies (6)
Dev Dependencies (7)
Dependents (0)

Copyright 2014 - 2016 © taobao.org |