Skip to content

upgrade toolchain and export gentype binding #21

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions bsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,9 @@
"suffix": ".js",
"warnings": {
"error" : "+101"
},
"gentypeconfig": {
"language": "typescript",
"module": "commonjs"
}
}
11 changes: 5 additions & 6 deletions examples/FetchExample.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

153 changes: 145 additions & 8 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
"main": "index.js",
"scripts": {
"test": "node tests/PromiseTest.js",
"build": "bsb -make-world",
"watch": "bsb -make-world -w"
"build": "rescript build",
"watch": "rescript build -w"
},
"files": [
"src/Promise.res",
Expand All @@ -23,7 +23,7 @@
"license": "MIT",
"devDependencies": {
"@babel/code-frame": "^7.12.11",
"bs-platform": "8.4.2",
"node-fetch": "^2.6.1"
"node-fetch": "^2.6.1",
"rescript": "^10.0.1"
}
}
6 changes: 6 additions & 0 deletions src/Promise.gen.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
/* TypeScript file generated from Promise.resi by genType. */
/* eslint-disable import/first */


// tslint:disable-next-line:interface-over-type-literal
export type t<a> = Promise<a>;
8 changes: 4 additions & 4 deletions src/Promise.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

43 changes: 22 additions & 21 deletions src/Promise.resi
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
//
// More details about polymorphism / invariance / covariance,... can be found here:
// https://caml.inria.fr/pub/docs/manual-ocaml/polymorphism.html#ss:variance:abstract-data-types
@genType
type t<+'a> = Js.Promise.t<'a>

// JsError is currently a shim exception and will be deprecated for
Expand All @@ -22,11 +23,11 @@ exception JsError(Js.Exn.t)
let p = Promise.resolve(5) // Promise.t<int>
```
")
@bs.val
@bs.scope("Promise")
@val
@scope("Promise")
external resolve: 'a => t<'a> = "resolve"

@bs.scope("Promise") @bs.val
@scope("Promise") @val
external reject: exn => t<_> = "reject"

@ocaml.doc("
Expand Down Expand Up @@ -55,8 +56,8 @@ Promise.make((resolve, reject) => {
->ignore
```
")
@bs.new
external make: ((@bs.uncurry (. 'a) => unit, (. 'e) => unit) => unit) => t<'a> = "Promise"
@new
external make: ((@uncurry (. 'a) => unit, (. 'e) => unit) => unit) => t<'a> = "Promise"

@ocaml.doc("
`catch(promise, errorCallback)` registers an exception handler in a promise chain.
Expand Down Expand Up @@ -116,7 +117,7 @@ Promise.resolve(5)
->ignore
```
")
@bs.send
@send
external then: (t<'a>, @uncurry ('a => t<'b>)) => t<'b> = "then"

@ocaml.doc("
Expand All @@ -137,7 +138,7 @@ resolve(\"Anna\")

In case you want to return another promise in your `callback`, consider using \`then\` instead.
")
@bs.send
@send
external thenResolve: (t<'a>, @uncurry ('a => 'b)) => t<'b> = "then"

@ocaml.doc("
Expand Down Expand Up @@ -171,11 +172,11 @@ resolve(5)
->ignore
```
")
@bs.send
@send
external finally: (t<'a>, unit => unit) => t<'a> = "finally"

/* Combining promises. */
@bs.scope("Promise") @bs.val
@scope("Promise") @val
external race: array<t<'a>> => t<'a> = "race"

@ocaml.doc("
Expand All @@ -196,41 +197,41 @@ all(promises)
->ignore
```
")
@bs.scope("Promise")
@bs.val
@scope("Promise")
@val
external all: array<t<'a>> => t<array<'a>> = "all"

@ocaml.doc("
[all2((p1, p2))]. Like `all()`, but with a fixed size tuple of 2
")
@bs.scope("Promise")
@bs.val
@scope("Promise")
@val
external all2: ((t<'a>, t<'b>)) => t<('a, 'b)> = "all"

@ocaml.doc("
[all3((p1, p2, p3))]. Like `all()`, but with a fixed size tuple of 3
")
@bs.scope("Promise")
@bs.val
@scope("Promise")
@val
external all3: ((t<'a>, t<'b>, t<'c>)) => t<('a, 'b, 'c)> = "all"

@ocaml.doc("
[all4((p1, p2, p3, p4))]. Like `all()`, but with a fixed size tuple of 4
")
@bs.scope("Promise")
@bs.val
@scope("Promise")
@val
external all4: ((t<'a>, t<'b>, t<'c>, t<'d>)) => t<('a, 'b, 'c, 'd)> = "all"

@ocaml.doc("
[all5((p1, p2, p3, p4, p5))]. Like `all()`, but with a fixed size tuple of 5
")
@bs.scope("Promise")
@bs.val
@scope("Promise")
@val
external all5: ((t<'a>, t<'b>, t<'c>, t<'d>, t<'e>)) => t<('a, 'b, 'c, 'd, 'e)> = "all"

@ocaml.doc("
[all6((p1, p2, p4, p5, p6))]. Like `all()`, but with a fixed size tuple of 6
")
@bs.scope("Promise")
@bs.val
@scope("Promise")
@val
external all6: ((t<'a>, t<'b>, t<'c>, t<'d>, t<'e>, t<'f>)) => t<('a, 'b, 'c, 'd, 'e, 'f)> = "all"
Loading