Convert Flow libdefs to Typescript declaration files.
This tool is currently pre-alpha. Contribution of issues, suggesions, and pull requests are welcome!
flow-to-dts input.flow.js output.d.ts
Transforming a code string:
import { transform } from 'flow-to-dts';
const input = 'type MyCode';
transform(input).then((output) => console.log(output));
Transforming an AST:
import { parse } from '@babel/parser';
import { transformAst } from 'flow-to-dts';
const input = parse('type MyCode');
transformAst(input).then((output) => console.log(JSON.stringify(output)));
(Note that this is not intended as an exhaustive list, but merely a representative sample indicating some of the key transformations performed by the tool.)
Feature | Supported | Flow | Typescript |
---|---|---|---|
Flow Header | ✔️ | // @flow |
// |
Module Exports | ✔️ | declare module.exports: MyModule; |
export = MyModule; |
Mixed Type | ✔️ | mixed |
number | string | boolean | symbol | object |
Nullable Types | ✔️ | ?string |
string | null | undefined |
Tuple Types | ✔️ | [number, string] |
[number, string] |
Exact Objects | ✔️ | {| name: string |} |
{ name: string } |
Open Objects | ✔️ | { name: string } |
{ name: string; [field: string]: any } |
Class Types | ✔️ | Class<SomeType> |
typeof SomeType |
Built-in Types | ✔️ | http$ClientRequest |
import { ClientRequest } from "http"; |
Key Types | ❌ | $Keys<A> |
|
Value Types | ❌ | $Values<A> |
|
Difference Types | ❌ | $Diff<A> |
|
Partial Types | ✔️ | $Shape<A> |
Partial<A> |
Rest Types | ❌ | $Rest<A> |
|
Supertypes | ❌ | $Supertype<A> |
|
Subtypes | ❌ | $Subtype<A> |
|
Existential Type | ✔️ | * |
any |
Special thanks to the creators and maintainers of the following projects that made this tool possible: