0.1.4 • Published 5 years ago
flow-to-dts v0.1.4
flow-to-dts
Convert Flow libdefs to Typescript declaration files.
This tool is currently pre-alpha. Contribution of issues, suggesions, and pull requests are welcome!
Usage
Command Line
flow-to-dts input.flow.js output.d.ts
Node API
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)));
Supported Features
(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 | :heavy_check_mark: | // @flow | // |
Module Exports | :heavy_check_mark: | declare module.exports: MyModule; | export = MyModule; |
Mixed Type | :heavy_check_mark: | mixed | number \| string \| boolean \| symbol \| object |
Nullable Types | :heavy_check_mark: | ?string | string \| null \| undefined |
Tuple Types | :heavy_check_mark: | [number, string] | [number, string] |
Exact Objects | :heavy_check_mark: | {\| name: string \|} | { name: string } |
Open Objects | :heavy_check_mark: | { name: string } | { name: string; [field: string]: any } |
Class Types | :heavy_check_mark: | Class<SomeType> | typeof SomeType |
Built-in Types | :heavy_check_mark: | http$ClientRequest | import { ClientRequest } from "http"; |
Key Types | :x: | $Keys<A> | |
Value Types | :x: | $Values<A> | |
Difference Types | :x: | $Diff<A> | |
Partial Types | :heavy_check_mark: | $Shape<A> | Partial<A> |
Rest Types | :x: | $Rest<A> | |
Supertypes | :x: | $Supertype<A> | |
Subtypes | :x: | $Subtype<A> | |
Existential Type | :heavy_check_mark: | * | any |
Acknowledgements
Special thanks to the creators and maintainers of the following projects that made this tool possible: