Currently I have a file src/index.re
. I also have a file src/util.js
which defines some helper functions I’d like to use. How do I use those functions in src/index.re
?
Asked
Active
Viewed 46 times
1

vkurchatkin
- 13,364
- 2
- 47
- 55

Derek Chiang
- 3,330
- 6
- 27
- 34
-
Have you tried the module syntax? You can find the docs here: https://bucklescript.github.io/docs/en/import-export.html – Neil Kistner Feb 24 '18 at 23:40
1 Answers
1
As Neil said in the comments, you'll want to use the bs.module
attribute.
Here's a concrete example:
[@bs.module "./util"] external helper : string => int = "";
This says that helper
is a function in ./util.js
that takes a string
and returns an int
. You can now use it as an ordinary function:
let n : int = helper("hello");

glennsl
- 28,186
- 12
- 57
- 75