Questions tagged [rescript]

ReScript is a language and compiler toolchain for building performant, easy-to-maintain JavaScript and ReactJS applications. It is a strongly typed language with many interoperability features to integrate nicely in existing JavaScript codebases.

Useful resources

78 questions
2
votes
1 answer

How to force a function to return 'unit' in Rescript?

I am trying to simulate a side effect of writing to DB with rescript. So I want to push the data in an array when calling repository.add. Js.Array.push returns an int, which I do not care about. I would like to force to return unit so that my…
JeromeBu
  • 1,099
  • 7
  • 13
2
votes
1 answer

Rescript and using ReProcessing

I've had a lot of trouble trying to install Reprocessing, a kind of basic graphics library that can be used from ReasonML or ReScript, and which has been updated in various ways, but the documentation/README is a bit incomplete, and various sources…
John
  • 509
  • 1
  • 6
  • 18
2
votes
1 answer

How to read JSON with unknown key in ReasonML?

I am writing a simple application that display dog images from Dog API. I used bs-json to make it a record and use it later. The list of breeds can be obtained by the API. The response looks like this. { "message": { "breed": ["array of…
2
votes
1 answer

How would I write a generic function to handle multiple record types in ReScript?

Given the following contrived example, is it possible to write a get function that can handle any record with an a property? type type_one = {a: int} type type_two = {a: int, b: int} let example_one = {a: 1} let example_two = {a: 1, b: 2} let get…
nickbreaton
  • 65
  • 1
  • 7
2
votes
1 answer

How to write short local open in ReScript?

This compiles in ReasonML: let testFn = who => Js.(log("Hello " ++ who ++ "!")); but not in ReScript: FAILED: src/test.ast Syntax error! /xxx/src/test.res:1:25-27 1 │ let testFn = who => Js.(log("Hello " ++ who ++ "!")); 2 │ I'm not…
menfon
  • 1,587
  • 1
  • 11
  • 28
2
votes
1 answer

Infinite Lists / Streams in ReScript

I can't seem to find the correct typing for an infinite list in ReScript. I first tried: type rec stream<'a> = ('a, () => ('a, stream<'a>)) Which was incorrect because ReScript thought the type was cyclic. So instead I tried: type rec stream<'a> =…
Ryan Schaefer
  • 3,047
  • 1
  • 26
  • 46
2
votes
3 answers

How do you call an uncurried function with unit in ReScript/ReasonML?

Say that I have an uncurried function like: let echo(. a) = a; I can call this funcition fine with most literals like: echo(. 1) echo(. "Hello") but when I am trying to call it with void, I get an error: echo(. ()) //This function has arity1 but…
namesis
  • 157
  • 10
2
votes
1 answer

How to get away from Non-capitalized key value for Record construction?

I am using graphql, nexus-plugin-prisma, prisma to build a backend application using ReScript. The problem I face is that there are some columns starting with capital letter, and I want to set types for such schemas using records instead of objects.…
Sanghyun Kim
  • 161
  • 1
  • 12
1
vote
1 answer

ReScript React how to import CSS files?

I am working on porting an existing React App to ReScript React, however I am running into a few issues. Namely I can't for the life of me figure out how to import CSS in ReScript, for example, In React to import Bootstrap all I would have to do…
Rawley Fowler
  • 1,366
  • 7
  • 15
1
vote
1 answer

npm build failing due to rescript cannot handle multiple files error

Error: rescript: [32/234] src/C...ts/Common/Transition.cmj FAILED: src/Components/Common/Transition.cmj can not handle multiple files Caused when I ran: npm start or yarn start bsconfig.json contents [name doesn't have any spaces] { "name":…
1
vote
1 answer

I tried to install Pupilfirst LMS

I tried to install Pupilfirst LMS, I had difficulty in step Compile Rescript Code: yarn run re: build Output: Usage Error: could't find a script named "re: build". And I also have difficulty in step Run Webpack Dev Server: yarn run wds Output:…
1
vote
1 answer

How can I use react-datepicker in the ReScript app

I`m trying to use an external library such as react-datepicker. My code and usage: module DatePicker = { @react.component @module("react-datepicker") external make: () => React.element = "default"; } @react.component let make = () => { …
Grigoryev
  • 47
  • 1
  • 5
1
vote
2 answers

Trouble translating JavaScript to ReScript

I wanted to implement an interactive slider using ReScript, so I wanted to translate this JavaScript to ReScript (courtesy: https://www.w3schools.com/howto/howto_js_rangeslider.asp): var slider = document.getElementById("myRange"); var output =…
Namudon'tdie
  • 306
  • 1
  • 10
1
vote
1 answer

Rescript-react: Creating a hidden canvas element

I am creating a simple react app (HTML) that allows a user to browse to an image on their local pc, and then displays it in an image tag. I want to take a data-url and dynamically create a hidden canvas tag (open to a different approach, but I want…
akaphenom
  • 6,728
  • 10
  • 59
  • 109
1
vote
0 answers

Add mouselistener on children

I'm using ReasonML. I would like to create a tooltip element. It should wrap a React.element and provide tooltip functionality, triggered by mouseevents. But I would not like it to appear in the DOM at all, because that can disrupt the layout. I've…