I’ve been getting better acquainted with interop bindings and I noticed that @val, which is throughout the documentation, doesn’t seem to matter. Every example binding I’ve found works fine after removing it. What dumb thing am I not noticing?
Is this some regression or accidental feature of v10.0.0, perhaps?
I get warnings like this in ReScript 9 when I remove any @val
, e.g.:
Unimplemented primitive used:resolved
See playground (switch to v9 on settings tab)
Ok I see this breaking change for 10.0.0, but I’m on 10.0.1. Whatever the problem, I wish I had waited a few weeks to look into bindings, I wouldn’t have been so confused
Externals without
@val
annotations do not work anymore, and externals with= ""
give an error.
- Example:
external setTimeout: (unit => unit, int) => float = "setTimeout"
is not supported anymore.- Fix: use
@val external setTimeout: (unit => unit, int) => float = "setTimeout"
instead.- Example2:
@val external setTimeout: (unit => unit, int) => float = ""
is not supported anymore.- Fix2: use
@val external setTimeout: (unit => unit, int) => float = "setTimeout"
instead.
But the external (at least in my playground example) still works without @val
in V10?
Edit: I literally copied the first example that “is not supported anymore” from the Changelog into the playground and it works:
https://rescript-lang.org/try?code=KYDwLsBOB2CGA2ACAzsMAVAlgW2AewFcwAuRACgOkzEQF4A+RS6gGkU2jAEo7GAzeHlg1aiAESoMOfETEAoOfDSJYdFGiy5CYMmR4NEAKWQA6QQHMyYsNPbJE2gIRiuXOcbN5LsN0A
IIRC, It is there for historical reasons. ReScript (or BuckleScript) used to require it to make it different from C style externals to avoid ambiguity, since we decided to focus on JS only, such restrictions are lifted at some time