Working on a Chrome plugin I got to use ClojureScript in yet another new environment. After the usual browser setup, Node, Deno and Github Actions, this time it was the Chrome plugin system. While it was mostly a very smooth ride, I had a little trouble figuring out how to deal with a “Cannot infer target type in expression” warning.

It showed up while dealing with a HAR entry object passed in to my callback from devtools.network.onRequestFinished. The HAR object, while its shape is well defined, is not typed in a strict sense (though I guess there may be some type definition for it somewhere out there if I looked hard enough). That’s why when I tried to access its fields like (-> entry .-request .-url) the ClojureScript compiler (through Shadow CLJS) would complain about inferring the “target type” as above.

The solution is probably obvious if you’re more used to CLJS than I am, but I didn’t even know what to search for. Turns out I was looking for the ^js annotation that helps smooth over rough edges like this when dealing with JS “externs”. So if using an arrow macro like above, it’s be like (-> ^js entry .-request ,,,).