Skip to content

burnnat/flow-to-dts

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

65 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

flow-to-dts

flow-to-dts Build Status Coverage Status

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 ✔️ // @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

Acknowledgements

Special thanks to the creators and maintainers of the following projects that made this tool possible:

About

Convert Flow libdef files to Typescript .d.ts definitions.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published