This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2022-11-16
Channels
- # announcements (7)
- # babashka (8)
- # beginners (48)
- # calva (4)
- # cider (6)
- # circleci (2)
- # clj-commons (14)
- # clj-kondo (3)
- # clj-on-windows (7)
- # cljs-dev (34)
- # clojure (49)
- # clojure-dev (25)
- # clojure-europe (48)
- # clojure-losangeles (1)
- # clojure-nl (4)
- # clojure-norway (33)
- # clojure-uk (2)
- # clojurescript (37)
- # community-development (5)
- # conjure (17)
- # cursive (2)
- # data-science (1)
- # editors (10)
- # emacs (50)
- # events (22)
- # honeysql (11)
- # introduce-yourself (1)
- # jobs-discuss (13)
- # lsp (42)
- # malli (9)
- # off-topic (7)
- # pathom (11)
- # portal (5)
- # re-frame (3)
- # reagent (22)
- # reitit (8)
- # reveal (1)
- # rewrite-clj (4)
- # shadow-cljs (38)
- # xtdb (21)
While fixing something in clj-kondo, I discovered that in .cljs
code Exception
and String
are not found as an unresolved symbol (due to a bug in kondo). I fixed that, but I'm left with some examples like:
(defn foo ^String [x] x)
which does compile in .cljs
correctly but I'm not sure if String
should be reported here as unresolved.
I think in this case it's clear:
(defn wrap-baz [^java.io.File x] (.getName x))
java.io.File
should be reported as something not known in CLJS (although the CLJS compiler doesn't complain on unknown types in hints), but I don't know if String
has any special meaning in the CLJS compiler or shadow-cljs.
I'm now leaning towards "it's not known in CLJS, so report" but let me know if it should be otherwiseThis happens mostly in .cljc
files , so maybe since CLJS is forgiving, the linter should not complain about unknown types in type hints either as far as CLJS is concerned?
And there is a deliberate choice of not reporting, like e.g. in
cljs.user=> (def x String)
^
WARNING: Use of undeclared Var cljs.user/String at line 1
? Perhaps to make it more convenient to write code in .cljc
files?resolving tags is different than resolving actual code, since JS is so dynamic knowing the actual class is not really important since there is no such thing as reflection
so in CLJ it is required and used. in CLJS it is optional. any none js
tag has no impact on inference
What would be the use of the tag if it is not going to impact inference or externs? Is it just fully useless on cljs without a js
?
well it does tell the compiler the type of something, but since JS has no types that doesn't really do much at all
in CLJ the type is required since it can directly emit a function call or so. if the type is not known it has to use reflection to call something, figuring stuff out at runtime
in CLJS that doesn't matter since you can just emit a direct function call either way
it can have impacts on protocol calls though. so its not totally useless in certain places, but often it does nothing
Thanks. That is helpful. I am familiar with clj and the jvm. I know js is more flexible in this regard. But good to understand the nuance.
not sure if this is an official tag. don't think so, meaning it doesn't have special meaning besides making externs inference warnings shut up
right. I thought I'd seen it in the wild but then that may be the de facto way of disabling those warnings - thanks
I might be wrong on this though. there is clj-nil
for sure with meaning in the analyzer, just not sure about clj
. I just use it to shut up externs inference
The not-native
type hint works in CLJS in clj-kondo because it's also something in CLJS core
cljs.user=> (doc not-native)
-------------------------
cljs.core/not-native
nil
I'll just make clj-kondo more relaxed about these type hints in CLJS so at least you don't have to branch out in .cljc
files to "undo" JVM type hints