Fork me on GitHub
#clojurescript
<
2023-01-03
>
athomasoriginal14:01:11

Today was the first time i've run into a type related issue (or so it seems):

(ns my-ns
  (:require 
    [goog.positioning :as gpositioning]
  (:import 
    [goog.positioning OverflowStatus])

  (let [status (gpositioning/positionAtCoordinate ...args) ; I return an int]
    (bit-and status OveerflowStatus/FAILED)))
     
The above triggers a CLJS compiler warning:
cljs.core/bit-and, all arguments must be numbers, got [goog.positioning.OverflowStatus nil] instead 
I can resolve by adding a type hint to the let binding (`^number status ...`), but just curious if anyone has seen something like this before.

valtteri19:01:54

You have a typo at least in the example >

OveerflowStatus/FAILED)

athomasoriginal19:01:59

True. That's not where the warning comes from, but thanks!

valtteri19:01:53

Got interested and started fiddling and trying to do a minimal repro. 🙂 This is not enough to cause a warning

(defn testing []
  OverflowStatus/FAILED)

(let [status (testing)]
  (bit-and 1 status))

athomasoriginal19:01:38

correct. That's because status needs to be (gpositioning/positionAtCoordinate ...args) (or at the least a function which returns an Overflow..but there is probably more to it because your example didn't work)

valtteri19:01:58

(let [status (gpositioning/getPositionAtCoordinate
              (gmath/Coordinate. 1 2)
              (gmath/Size. 100 200)
              Corner/TOP_LEFT)]
  (bit-and OverflowStatus/ADJUSTED_X status))

valtteri19:01:19

What is the exact compiler warning you’re seeing?

athomasoriginal19:01:52

Whats in the code block in the original message 🙂

valtteri19:01:23

Time for me to go to sleep soon 🙂

😆 2
valtteri19:01:40

Anyways, I’m not seeing the warning with the latest example I posted. It’s probably doing nonsense because I just tried to feed the function something.

valtteri19:01:52

Now I see I picked the wrong function as well.. 😄

valtteri19:01:07

There’s both getPosition... and without get

athomasoriginal19:01:55

you want positionAtCoordinate

athomasoriginal19:01:22

or positionAtAnchor

valtteri19:01:43

Something weird definitely here. closure reference docs show the first and second arg types as > (https://google.github.io/closure-library/api/goog.math.Coordinate.html|null) > (Element|null)

valtteri19:01:53

The |null part looks fishy

Jakub Holý (HolyJak)20:01:05

I see cljs has no amap so how do I map over a #js array? Do I need to (.map <js array>) ? Thx! Ah, there is amap! It is just missing from https://cljs.info/cheatsheet/ for some reason…

lilactown17:01:51

map also works with JS arrays

lilactown17:01:08

map works with anything that is iterable

Jakub Holý (HolyJak)17:01:50

Ah, I believed I got an error when I tried that but you are right, it works. Thank you!

wcohen21:01:04

trying to resurrect an old attempt at emscripten interop on a cljs project, but trying to restart a repl via clj -M -m cljs.main -co build.edn is resulting in a cryptic Execution error at cljs.vendor.clojure.data.json/read-object ... JSON error empty entry in object is not allowed -- anyone get this before and know what it's pointing to?

wcohen21:01:35

it's generally built off the webpack guide