This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2019-02-03
Channels
yeah but you are calling it with elem
and the clj->js
result (which is not a boolean)
(defn scroll-to-id
[target-id]
(-> (js/document.getElementById target-id)
(.scrollIntoView #js {:behavior "smooth" :inline "nearest"})))
How do we use type hints in Clojurescript and how does it relate with type inference?
I am running this code snippet on version 1.10.516
:
(defn bar [^number x]
(inc x))
(bar "abc")
And I don’t get any warning.
While the following snippet creates a warning
(inc "abc")
cljs.core/+, all arguments must be numbers, got [string number] instead
@viebel pretty sure that is reserved to special js forms currently and not supported via type hints
@viebel The core numeric macro-functions do this. Outside of this I’m struggling to think of any other specific examples.
@mfikes I see. Any idea why in my 1st example above no warning is emitted?
@viebel Because ClojureScript doesn't generally use type information to perform type checking. There was an experiment that, as an aside, involved adding generic type checking (https://gist.github.com/mfikes/1e2341b48b882587500547f6ba19279d), but ClojureScript probably isn't pursuing that direction.
ClojureScript has always had basic type inference, and the algorithms have been improving, so that more types are inferred. This is especially true over the past several releases, IMHO.
I understand that the algorithms are improving. My question is what value does it bring to developers?
Is it in terms of type checking or more efficient transpiled code or something else?