Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/green-labs/ppx_ts
ReScript PPX helps the binding to typescript modules
https://github.com/green-labs/ppx_ts
Last synced: about 2 hours ago
JSON representation
ReScript PPX helps the binding to typescript modules
- Host: GitHub
- URL: https://github.com/green-labs/ppx_ts
- Owner: green-labs
- Created: 2022-02-14T16:19:26.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2024-06-18T09:22:01.000Z (5 months ago)
- Last Synced: 2024-10-31T09:37:10.303Z (12 days ago)
- Language: OCaml
- Size: 209 KB
- Stars: 36
- Watchers: 8
- Forks: 2
- Open Issues: 5
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
Awesome Lists containing this project
README
# PPX_ts
`ppx_ts` is a ReScript preprocessor, which helps generating helper types to bind to typescript modules.
## Install
```rescript
yarn add -D @greenlabs/ppx-ts
``````rescript
// bsconfig.json
"ppx-flags": [
...,
"@greenlabs/ppx-ts/ppx"
],
```## Features
### Attributes `@`
#### `keyOf`
```rescript
@ppx_ts.keyOf
type t = {
name: string,
age: int
}// automatically generated
type t_keyOf = Name | Age// automatically generated
let t_keyToString = key =>
switch key {
| Name => "name"
| Age => "age"
}
```#### `setType(t)`
```rescript
module Error = {
type t
}
@ppx_ts.setType(Error.t)
type t = {
name: string,
age: int
}// automatically generated
type t_setType = {
name: Error.t
age: Error.t
}
```#### `toGeneric`
```rescript
@ppx_ts.toGeneric
type t = {
name: string,
age: int
}// automatically generated
type t_toGeneric<'a> = {
name: 'a
age: 'a
}
```#### `partial`
```rescript
@ppx_ts.partial
type t = {
name: string,
age: int
}// automatically generated
type t_partial = {
name: option,
age: option
}
```#### `pick`
```rescript
@ppx_ts.pick(["name"])
type t = {
name: string,
age: int
}// automatically generated
type t_pick_name = {
name: string,
}
```#### `omit`
```rescript
@ppx_ts.omit(["name"])
type t = {
name: string,
age: int
}// automatically generated
type t_omit_name = {
age: int,
}
```#### `toArray`
```rescript
@ppx_ts.toArray
type t = Name | Age// automatically generated
let t_toArray = ["Name", "Age"]
```### Extension `%`
#### `keyOf`
```rescript
module Error = {
type t = {
name: string,
age: int
}
}@spice // attributes are available
type t1 = %ppx_ts.keyOf(Error.t) // type t1 = Name | Age// automatically generated
let t1_keyToString = key =>
switch key {
| Name => "name"
| Age => "age"
}
```#### `setType`
```rescript
type t = {
name: string,
age: int
}@spice // attributes are available
type t1 = %ppx_ts.setType((t, string))
// changed
type t1 = {
name: string
age: string
}
```#### `setTypeExceptBool`
```rescript
type t = {
name: string,
age: int,
isKorean: bool
}@spice // attributes are available
type t1 = %ppx_ts.setTypeExceptBool((t, string))
// changed
type t1 = {
name: string,
age: string,
isKorean: bool
}
```#### `toGeneric`
```rescript
type t = {
name: string,
age: int
}@spice // attributes are available
type t1 = %ppx_ts.toGeneric(t)
// generated
type t1<'a> = {
name: 'a
age: 'a
}
```#### `partial`
```rescript
type t = {
name: string,
age: int,
isKorean: bool
}@spice // attributes are available
type t1 = %ppx_ts.partial(t)
// generated
type t1 = {
name: option,
age: option,
isKorean: option
}
```## Contribution
1. Create a sandbox with opam
```
opam switch create ppx_ts 4.12.1
```2. Install dependencies
```
opam install . --deps-only --with-test
```3. Build
```
opam exec -- dune build
```4. Test
```
cd rescript(install dependencies)
yarn(build --watch)
yarn res:clean && yarn res:watch(run test --watch)
yarn test:watch
```