https://github.com/ocsigen/ts2ocaml
Generate OCaml bindings from TypeScript definitions via the TypeScript compiler API
https://github.com/ocsigen/ts2ocaml
Last synced: 12 days ago
JSON representation
Generate OCaml bindings from TypeScript definitions via the TypeScript compiler API
- Host: GitHub
- URL: https://github.com/ocsigen/ts2ocaml
- Owner: ocsigen
- License: apache-2.0
- Created: 2020-04-08T03:14:27.000Z (about 5 years ago)
- Default Branch: main
- Last Pushed: 2024-05-10T00:32:51.000Z (11 months ago)
- Last Synced: 2024-05-11T00:40:49.618Z (11 months ago)
- Language: F#
- Homepage:
- Size: 26.7 MB
- Stars: 162
- Watchers: 14
- Forks: 6
- Open Issues: 12
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE.md
Awesome Lists containing this project
- awesome-technostructure - ocsigen/ts2ocaml
- awesome-technostructure - ocsigen/ts2ocaml
README
ts2ocaml
========[](https://www.npmjs.com/package/@ocsigen/ts2ocaml)
[](https://www.npmjs.com/package/@ocsigen/ts2ocaml)Generate OCaml bindings from TypeScript definitions via the TypeScript compiler API.
## Installation
> Try out v2 beta!
>
> `npm install -g @ocsigen/ts2ocaml@beta````
npm install -g @ocsigen/ts2ocaml
```Or if you are using yarn:
```
yarn global add @ocsigen/ts2ocaml
```An in-browser version may be available in future.
## Overview
**Goals:**
* Provide a way to quickly generate a missing binding to some JS package you need in your project.
- This tool can generate OCaml bindings to JS packages from TS definition files (`.d.ts`), which you can use with minimal modification.
* Help library authors by reducing the amount of boilerplate code they have to write by hand.
- This tool can be configured to generate an imperfect but simpler version of bindings, which you can easily modify to create a better binding library.**Non-goals:**
* Generate a binding written in 100% OCaml-idiomatic way.
- OCaml has very different programming concepts from TypeScript, so it's not very straightforward to translate TypeScript's concepts to OCaml's one.
- This tool will simply generate bindings which closely resembles the original TypeScript definitions. It's human's job to translate it to OCaml-idiomatic API.
* Perfectly replicate TypeScript's type system in OCaml.
- Many of [the advanced types in TypeScript](https://www.typescriptlang.org/docs/handbook/2/types-from-types.html), such as `keyof T` or `T extends U ? A : B`, are simply impossible to simulate in OCaml.
- In those cases, this tool will leave them as untyped. It's also human's job to (possibly) restore type safety with some other means.## Documentation
For users:
- [Common options](docs/common_options.md) among all the targets
- [ts2ocaml for js_of_ocaml](docs/js_of_ocaml.md)
- [ts2ocaml for ReScript](docs/rescript.md)For developers and contributors:
- [Overview for developers](docs/development.md)
- [Note on modeling TS subtyping in OCaml](docs/modeling_subtyping.md)## About this tool
This tool is heavily inspired by [fable-compiler/ts2fable](https://github.com/fable-compiler/ts2fable), which generates [Fable](https://fable.io/) (F# AltJS) bindings from TS definition files.
This tools is licensed under the [Apache License 2.0](LICENSE.md).