This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2018-05-28
Channels
- # announcements (1)
- # beginners (183)
- # boot (2)
- # clara (4)
- # cljs-dev (20)
- # clojure (59)
- # clojure-dev (7)
- # clojure-nl (1)
- # clojure-serbia (1)
- # clojure-sg (1)
- # clojure-spec (4)
- # clojure-uk (15)
- # clojurescript (77)
- # clr (1)
- # data-science (9)
- # datomic (23)
- # docs (3)
- # duct (15)
- # emacs (8)
- # events (1)
- # fulcro (6)
- # instaparse (3)
- # juxt (1)
- # lumo (9)
- # off-topic (18)
- # perun (2)
- # portkey (13)
- # reagent (2)
- # reitit (11)
- # ring (10)
- # shadow-cljs (158)
- # tools-deps (34)
has there been any talk about supporting a plain ^js
annotation for externs inference?
I’ve been using this via shadow-cljs for a long time now and it’s really nice; I’d like to use it for libraries that can be :advanced
compiled w/o shadow-cljs
hmm I can check again. I thought I had run into a problem w/ this some months ago but my memory could be mistaken
It looks like, in that case, you get externs added to Object
(along with a compiler warning that it is doing this)
WARNING: Adding extern to Object for property baz due to ambiguous expression (. x baz) at line 7 /Users/mfikes/Desktop/src/my_project/core.cljs
if you replace ^js/Foo.Bar
with just ^js
in the example at https://clojurescript.org/guides/externshmm I am trying to figure out why this “just works”, without annotation, and no warning is shown:
(ns js-test)
(set! *warn-on-infer* true)
(js* "window.x = {\"greeting\": \"Hello!\"} ")
(js/console.log "without annotation", (.. js/window -x -greeting))
given:
(js/eval "function someObj () {return {\"greeting\": \"Hello!\"}};")
works, with a warning: (no hint)
(println (.-greeting (js/someObj)))
does not work at all: (no hint, same thing but passed through a function)
(defn print-greeting [obj]
(println (.-greeting obj)))
(print-greeting (js/someObj))
works, with a warning: (hint in arglist)
(defn print-greeting [^js obj]
(println (.-greeting obj)))
(print-greeting (js/someObj))
yes but if you do not (set! *warn-on-infer* true)
it still generates the externs right?
yes I think so interesting, if I put some random non-^js thing as the hint, there is no warning, and it does not work:
(defn print-greeting [^someRandomHint obj]
(println (.-greeting obj)))
(print-greeting (js/someObj))