Fork me on GitHub
#clojurescript
<
2024-02-21
>
cap10morgan21:02:46

I am generating TypeScript types from the compiled JS in a CLJS project, but my multi-arity fns are compiled into JS fns taking the max number of args but then branching on arguments.length. That makes the TypeScript compiler complain that I'm not supplying enough args when I invoke lower-arity versions of those fns in TS consumers of the CLJS lib. Is there a way to get it to use rest parameters (e.g. function sum(...theArgs)) in the compiled JS output? Or is anyone aware of some other solution to that?

thheller22:02:40

that part of CLJS is from a time before rest/spread existed in JS, so everything is still using arguments. so no, there is no way to get this

thheller22:02:01

no clue about TS stuff, never used any of it

cap10morgan02:02:57

OK, thanks for that info. That's what I would have bet money on being the answer. 🙂

Jérémie Pelletier23:02:23

whats the recommended way to use binding with async flows? ie js/Promise.then or reagent-render functions

thheller23:02:10

recommended: don't 😛 I mean seriously, don't use binding at all in async code

Jérémie Pelletier23:02:35

yeah doesn't have to be binding itself, a workaround is fine

Jérémie Pelletier23:02:21

im thinking attaching a binding context to Promise instances, and providing a custom then function to wrap the callback to set/unset the dynamic vars over the call

Jérémie Pelletier23:02:20

thing is I have functions looking at <current selection> and applying changes there, and I want bindings to override this at the call site, with code in between which is completely unaware of this mechanism to the point it cant thread it through params

Jérémie Pelletier23:02:45

for reagent I hack around this with (set!) inside the render function, so nested calls which are always sequential get access to the data; its really ugly as a hack but also works; however for promises im unsure because the execution order is undefined

Jérémie Pelletier15:02:53

Essentially, what I'm looking for is "fiber local storage" but for async in javascript/clojurescript