shadow-cljs

https://github.com/thheller/shadow-cljs | https://github.com/sponsors/thheller | https://www.patreon.com/thheller
martinklepsch 2020-12-03T12:19:49.328500Z

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

martinklepsch 2020-12-03T12:22:59.329600Z

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.

martinklepsch 2020-12-03T12:24:43.330200Z

I only get those warnings when requiring the namespace inside shadow-cljs node-repl — when evaluating via Conjure/Vim they are not shown

martinklepsch 2020-12-03T12:25:23.330800Z

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

thheller 2020-12-03T12:49:59.331500Z

@martinklepsch I think (defn foo ^ReturnType [a b] ...)

thheller 2020-12-03T12:50:12.331800Z

don't know about infer warnings, need more info

martinklepsch 2020-12-03T12:57:17.333Z

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] ....

thheller 2020-12-03T12:57:53.333400Z

^sentry.Scope has no meaning in shadow-cljs whatsoever. just make your life easier and use ^js

thheller 2020-12-03T12:58:43.334Z

you might not get be inference warnings because shadow-cljs processes the JS for browser builds, so it collects more externs infos

thheller 2020-12-03T12:58:51.334400Z

that is not done for node builds since they load stuff directly via node

martinklepsch 2020-12-03T13:01:26.335200Z

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)

martinklepsch 2020-12-03T13:02:00.335800Z

that said the example above was more about the undeclared-var warning and less about inference

thheller 2020-12-03T13:02:03.336Z

maybe your editor just doens't show it? I don't know. need more info.

thheller 2020-12-03T13:02:21.336400Z

undeclared var what? you only pasted a chunk of code

thheller 2020-12-03T13:02:30.336700Z

what is undeclared there?

martinklepsch 2020-12-03T13:02:33.336800Z

Use of undeclared Var icebreaker.util.sentry/sentry

thheller 2020-12-03T13:02:44.337200Z

thats the ^sentry.Scope probably. should be either ^js or sentry/Scope given that its an alias not a var

martinklepsch 2020-12-03T13:04:32.338100Z

I also get it on lines that don’t have the sentry.Scope hint and it persists after removing the sentry.Scope hints

thheller 2020-12-03T13:05:46.338900Z

I don't know. I can't guess without seeing the code.

thheller 2020-12-03T13:06:21.339400Z

one thing though. if you have :as something you should probably always be treating that as a proper namespace alias

thheller 2020-12-03T13:06:42.340100Z

while (.configureScope sentry ...) is valid (sentry/configureScope ...)would be better

martinklepsch 2020-12-03T13:13:05.340500Z

oh I see, maybe I’ll just try that

martinklepsch 2020-12-03T13:16:33.340800Z

hm, that still gives me

No such namespace: sentry, could not locate sentry.cljs, sentry.cljc, or JavaScript source providing "sentry"

martinklepsch 2020-12-03T13:18:09.341100Z

here’s the full source for this namespace: https://gist.github.com/martinklepsch/0a146f46dfc7a304eaec0f348e5a5d36

thheller 2020-12-03T14:04:46.341900Z

@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.

martinklepsch 2020-12-03T14:06:04.342900Z

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

thheller 2020-12-03T14:26:28.343500Z

you can set :target-defaults {:node-script {:compiler-options {:reader-features ...}}}. that should apply to node-repl

1🙌