thanks! I now noticed that when requiring some of my namespaces in the node repl I get lots of infer-warnings and - if I remember correctly - this previously impacted async evaluations at the REPL
is there a way to type hint the return value of a function at the place where the function is defined? I have some functions that return JS objects and hinting those in every place I use them is a little tedious/noisy.
I only get those warnings when requiring the namespace inside shadow-cljs node-repl
— when evaluating via Conjure/Vim they are not shown
Also I’m noticing that the warnings only occur when requiring the namespace in a node-repl. The actual builds using those files don’t log any warnings
@martinklepsch I think (defn foo ^ReturnType [a b] ...)
don't know about infer warnings, need more info
Interestingly a large chunk also seems to be undeclared-var
warnings from something like this:
(:require #?(:node
["@sentry/node" :as sentry]
:browser
["@sentry/browser" :as sentry])
(.configureScope sentry (fn [^sentry.Scope scope] ....
^sentry.Scope
has no meaning in shadow-cljs whatsoever. just make your life easier and use ^js
you might not get be inference warnings because shadow-cljs processes the JS for browser builds, so it collects more externs infos
that is not done for node builds since they load stuff directly via node
I do get the inference warnings when starting the node repl via shadow node-repl
, just not when evaluating through my editor (so probably not shadow’s fault)
that said the example above was more about the undeclared-var
warning and less about inference
maybe your editor just doens't show it? I don't know. need more info.
undeclared var what? you only pasted a chunk of code
what is undeclared there?
Use of undeclared Var icebreaker.util.sentry/sentry
thats the ^sentry.Scope
probably. should be either ^js
or sentry/Scope
given that its an alias not a var
I also get it on lines that don’t have the sentry.Scope hint and it persists after removing the sentry.Scope hints
I don't know. I can't guess without seeing the code.
one thing though. if you have :as something
you should probably always be treating that as a proper namespace alias
while (.configureScope sentry ...)
is valid (sentry/configureScope ...)
would be better
oh I see, maybe I’ll just try that
hm, that still gives me
No such namespace: sentry, could not locate sentry.cljs, sentry.cljc, or JavaScript source providing "sentry"
here’s the full source for this namespace: https://gist.github.com/martinklepsch/0a146f46dfc7a304eaec0f348e5a5d36
@martinklepsch now I see. you don't have a :cljs
default branch for sentry
. node-repl
doesn't use any custom reader conditionals so it only uses :cljs
which is missing.
oh, true, I do mostly start my node-repl like this (shadow/node-repl {:config-merge [{:compiler-options {:reader-features #{:node}}}]})
but you’re right that when I tried to reduce the repro I skipped that
you can set :target-defaults {:node-script {:compiler-options {:reader-features ...}}}
. that should apply to node-repl