Questions tagged [bucklescript]

BuckleScript was previously known as a compiler for compiling OCaml to efficient JavaScript code. It has now evolved into the ReScript language. Use the [rescript] tag instead.

BuckleScript was previously known as a back-end for which emits readable, modular and highly performant JavaScript.

On July 2020, BuckleScript (and some parts of the ReasonML syntax) evolved into the ReScript language platform. The term "BuckleScript" is therefore deprecated. Use the tag for BuckleScript specific questions instead.

Useful resources

Related tags

181 questions
2
votes
1 answer

Record with optional and mutable fields

In the docs: https://bucklescript.github.io/docs/en/object.html there are examples for a record with mutable fields and optional fields. When I try to use both it fails: Compiles: type person = { mutable age: int; job: string; } [@@bs.deriving…
kunigami
  • 3,046
  • 4
  • 26
  • 42
2
votes
1 answer

How to cast a promise error to a custom type?

Hej, I have this piece of code BsFirebase.Auth.signInWithEmailAndPassword( Firebase.auth, ~email=self.state.email, ~password=self.state.password, ) |> Js.Promise.then_(_user => { // ... }) |> Js.Promise.catch((error) => { // ... }) |>…
ThomasThiebaud
  • 11,331
  • 6
  • 54
  • 77
2
votes
3 answers

Reason/Bucklescript + bs-jest: How to compile files with a *.test.re pattern outside of __tests__ folder?

Background: I am currently using bs-jest for unit testing. In addition, I am using the bsb init project, meaning that I am first compiling files using Reason/Bucklescript + then running compiled files using Webpack. Jest by default will pick up…
Charlie-Greenman
  • 1,469
  • 1
  • 16
  • 36
2
votes
1 answer

What is the difference between .() and .{} in Reason?

I'm trying to figure out why the example for using Js.Promise uses Js.Promise.( ... ) Whereas the example for Json.Decode uses Json.Decode.{ ... } From what I understand, .() opens up Js.Promise so that I can just call any function within…
csb
  • 674
  • 5
  • 13
2
votes
1 answer

How to protobuf in ReasonML?

I have a set of protobuf types, and I want to generate reasonML code for serialization. What I've found so far is ocaml-protoc which fails to install on my system. Using docker, FROM ocaml/opam:alpine RUN opam remote add dev…
Keynan
  • 1,338
  • 1
  • 10
  • 18
2
votes
2 answers

What's the proper way to deal with Js.Nullable?

I'm trying to do something like the following: let str_result: Js.Nullable.t(string) = Js.Nullable.return("something"); let int_result: Js.Nullable.t(int) = Js.Nullable.fromOption(Some(5)); Js.log([|str_result, int_result|]); But of course, I get…
csb
  • 674
  • 5
  • 13
2
votes
1 answer

Unable to type polymorphic [%bs.raw function

1) Is there a way to type this? 2) Anyone able to expound on these error messages? let identity1: 'a => 'a = [%bs.raw {| function(value) { return value } |}]; /* Line 2, 11: The type of this expression, '_a -> '_a, contains type variables…
M. Walker
  • 603
  • 4
  • 14
2
votes
1 answer

Firebase deploy failed because javascript file inside of node module cannot be found

I've got a project (written in Reason, but compiling to JS) that uses the module https://www.npmjs.com/package/bs-express. When the code is compiled, the require statement for that module looks like this: var Express =…
Murphy Randle
  • 816
  • 10
  • 19
2
votes
1 answer

proper way to initialize a bucklescript project for the browser

I can create, compile and run a bucklescript project with the following commands bsb -init new-project cd new-project npm run build node ./src/demo.bs.js However, I'd like to use the definitions in the generated demo.bs.js from a script embedded in…
user9309163
2
votes
1 answer

Fetch rejects promise on 404 responses instead of resolving with 404 status

I'm trying to figure out how to process failed http responses in the fetch example in reason-react-example repo. The following was my first idea (tinkering with the url): Js.Promise.( Fetch.fetch("https://dog.ceo/api/breeds/list") …
2
votes
1 answer

Selecting elements from the DOM - Reasonml/BuckleScript querySelector

How would you select items from the DOM using Reason. I'm using bs-webapi for the DOM bindings here is what I want to do: let parent = document |> Document.querySelector(".parent"); let child = Element.querySelector(".child", parent); However,…
Steven Scaffidi
  • 2,280
  • 1
  • 12
  • 14
2
votes
1 answer

bs-webapi - How to loop over Dom.nodeList?

The following won't work since sides is a Dom.nodeList and DomTokenList.forEach expects a Dom.domTokenList. open Bs_webapi.Dom; external length : Dom.nodeList => int = "" [@@bs.get]; let sides = Document.querySelectorAll "#carousel > figure"…
Raphael Rafatpanah
  • 19,082
  • 25
  • 92
  • 158
2
votes
1 answer

Print module signature of a file using Merlin

Using Merlin 2.5.4, what is the correct way to print the signature of an OCaml file in my project? E.g., suppose I have: (* foo.ml *) let x = 1 And I want to get: val x : int What is the proper command (or sequence of commands)? What I've tried: I…
Yawar
  • 11,272
  • 4
  • 48
  • 80
2
votes
2 answers

How to set DOM attribute (i.e. style) using Reason/Bucklescript?

How would I write the following JavaScript: var element = document.querySelector('.element') element.style.color = 'red' in Reason? So far I have: [@@@bs.config {no_export: no_export}]; external document : Dom.document = "document"…
Raphael Rafatpanah
  • 19,082
  • 25
  • 92
  • 158
2
votes
1 answer

How to encode a list of records to JSON in Reason?

Given a record type and a list of records: type note = { text: string, id: string }; let notes: list complete_note = [{text: "lol", id: "1"}, {text: "lol2", id: "2"}] How do I encode this to JSON using bs-json module? What I tried: I tried to…
Michał Miszczyszyn
  • 11,835
  • 2
  • 35
  • 53