Description
One of the features of the @as
decorator in externals is it can inject and erase function arguments, filling them with a value. This leads to an interesting (but niche) side-effect, where using @as
within an @obj
decorator allows object properties to be erased and filled with a value. Or at least it used to; uncurried mode breaks this.
One of the libraries I work on makes use of the technique, to model a NodeJS API that changes type based on a config option. The details are a bit complicated so I built a simplified playground example.
Change that to v11 and it prints a very strange error where more arguments are "required" than the type it prints:
This uncurried function has type
(
~read: (t, ~size: Js.nullable<int>) => unit,
~autoDestroy: bool=?,
unit,
) => configObj
It is applied with 2 arguments but it requires 4.
It seems that while @as
does still inject the argument, in uncurried mode it fails to completely erase it. A further effect of this is to break optional argument handling (when this first happened I thought uncurried @obj
no longer supported optional arguments).
Further discussion on the forum
https://forum.rescript-lang.org/t/the-big-migration-thread-for-rescript-v11-and-uncurried-mode/4769/37?u=spyder