Fork me on GitHub
#shadow-cljs
<
2020-12-03
>
martinklepsch12:12:49

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

martinklepsch12:12:43

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

martinklepsch12:12:59

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.

martinklepsch12:12:23

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

thheller12:12:59

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

thheller12:12:12

don't know about infer warnings, need more info

martinklepsch12:12:17

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

thheller12:12:53

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

thheller12:12:43

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

thheller12:12:51

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

martinklepsch13:12:26

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)

martinklepsch13:12:00

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

thheller13:12:03

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

thheller13:12:21

undeclared var what? you only pasted a chunk of code

thheller13:12:30

what is undeclared there?

martinklepsch13:12:33

Use of undeclared Var icebreaker.util.sentry/sentry

thheller13:12:44

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

martinklepsch13:12:32

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

thheller13:12:46

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

thheller13:12:21

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

thheller13:12:42

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

martinklepsch13:12:05

oh I see, maybe I’ll just try that

martinklepsch13:12:33

hm, that still gives me

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

thheller14:12:46

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

martinklepsch14:12:04

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

thheller14:12:28

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

🙌 3