$ npm install --global reasonably-typed
// class.js
declare module 'classes' {
declare type State = {
id: number,
storeName: string,
}
declare export class Store {
constructor(initialState: State): Store;
state: State;
update(nextState: State): void;
}
}
$ retyped class.js
/* Module classes */
type state = {. "id": float, "storeName": string };
module Store = {
type t = {. "state": (state), "update": [@bs.meth](state => unit)};
[@bs.new] [@bs.module "classes"] external make : state => t = "Store";
};
type state = < id :float ;storeName :string > Js.t
module Store =
struct
type t = < state :state ;update :((state -> unit)[@bs.meth ]) > Js.t
external make : state -> t = "Store"[@@bs.new ][@@bs.module "classes"]
end
TypeScript has a similar workflow. Compile your TypeScript file with:TypeScript
$ retyped my-definition.d.ts
Command-line Usage
Usage:
$ retyped ...files
Examples:
$ retyped file1.js file2.js file3.d.ts [boolean]
Formats a block of code using Compiles a libdef, formats the result, and handles errors cleanlyUsage as a library
ReasonablyTyped also exports a library for use! See the example below:
// lib-usage.js
import * as ReasonablyTyped from 'reasonably-typed'
const libSrc = fs.readFileSync('lib.js').toString()
const bsInterface = ReasonablyTyped.compile(libSrc)
format (code: string) => string
refmt
compile (code: string, filename?: string) => string
See DEVELOPING and CONTRIBUTING.