Convert Js.Global.intervalId to integer

How do I turn a Js.Global.intervalId into an integer?

What’s your use case?

I’m creating a programming language.

I just want to use a primitive type.

It’s already a primitive type under the hood (a JS number) so you don’t have to make any conversion.

If you want it to be recognized as an int by the type system (but I still haven’t understood the use case), you can just use an identity conversion:

external intervalIdToInt: Js.Global.intervalId => int = "%identity"

Do intervalId values fit within the bounds of ReScript int? It might not be type-safe to cast them. Generally for JS number type it’s safer to use ReScript float type.

1 Like

That’s a valid concern, anyway it’s hard to answer without understanding how it’ll be used.

1 Like

I ended up not converting it. Thanks anyway.