Fork me on GitHub
Fredrik Wallberg19:04:50

Looking at the recently added example projects, it seems like Typed Clojure partially supports type checking Clojurescript now. Amazing! Are there any limitations? Which issues would I run into if I tried to check a "real-world" project with javascript interop, DOM manipulations etc.?


@wallberg thanks! type checking js interop is completely missing atm. IIRC dot forms just take and accept anything.


There are a bunch of macros that need special support. reify comes to mind. But if Typed Clojure doesn't support it, you'll get an incomprehensible type error (unless you're familiar with the details of that particular macro's expansion).


But I anticipate anything "frameworky" that has its own macros will need special support.


I'm waiting for someone to try it out on something real. I'm a lot more confident that I can address problems now. Many things were basically impossible with the old approach.


I'm working on extend-type for cljs, as it's different than CLJ. And Typed Clojure doesn't reason about metadata, so cljs.core/type usage is completely lost on the type checker.


The state of things for ClojureScript is basically that the groundwork is there to extend the type checker with new annotation and rules, but we might need a small army to populate them to everyones satisfaction (like say the effort behind clj-kondo).


So community involvement is important now.


The other main headache relates to both CLJ+CLJS, and that's all local function args need annotations (I think people are ok with global annotations). That's probably what I will tackle next.


No one wants to change (map #(inc %) ...) to (map (t/fn [a :- t/Int] (inc a)) ...)


If I have a steady stream of real world feature requests I can probably address those in the hammock time for that problem (it's really hard).

Fredrik Wallberg21:04:02

This is very useful information and great news, thanks a lot! I usually try to separate (i.e. in different files) the pure Clojurescript "logic" from javascript interop anyway, so missing interop isn't a blocker for me personally. Type checking entire Clojurescript programs which use e.g. re-frame and js libraries like Prosemirror would of course be nice. But even if that were possible, I might prefer leaving some code unchecked and use strict type guards at the boundaries between typed and untyped code. At least that's what I sometimes ended up doing in Purescript.


Separating interop works well for type checking too. You'd use (t/ann ^:no-check my-fn-that-uses-interop [Foo -> Bar]) to avoid checking the def.

👍 1