Fork me on GitHub
#core-typed
<
2022-04-02
>
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.?

ambrosebs20:04:20

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

ambrosebs20:04:22

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

ambrosebs20:04:44

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

ambrosebs20:04:49

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.

ambrosebs20:04:43

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.

1
ambrosebs20:04:51

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

ambrosebs20:04:43

So community involvement is important now.

1
ambrosebs20:04:28

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.

ambrosebs20:04:28

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

ambrosebs20:04:44

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

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

ambrosebs21:04:44

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