Typed Clojure 1.0.27 - Check your programs without depending on typedclojure!
Published on April 12, 2022 by Ambrose Bonnaire-Sergeant
Hi Patrons,
I've been progressing on annotating malli, and I've made several fixes and improvements in 1.0.27 based on that experience.
One thing that I have to mention first (as it's a great feeling) is that annotating malli with Typed Clojure annotations actually revealed a bug in malli. It seems small, but it's a massive success and very motivating. Check out the PR fixing it: https://github.com/metosin/malli/pull/690
Anyway, I know that if libraries like malli could ever adopt Typed Clojure to check their implementation, they must be able to ship a jar with no trace of Typed Clojure (at least, in their required dependency chain). This was not really possible in practice: you could move global annotations to a separate ns, but local annotations must be provided by macros like `typed.clojure/ann-form` or wrappers like `typed.clojure/fn`.
This release starts to fix that. Now you can annotate `clojure.core/fn` parameters directly without ever loading Typed Clojure. A new Clojure 1.11 feature `:as-alias` makes this almost not look horrible. Let's juxtapose the two styles.
With runtime dependency:
```
(ns ...(:require [typed.clojure :as t])) ;; actually load typed.clojure
(... (t/fn [a :- t/Int]) ...) ;; uses macro typed.clojure/fn to annotate
```
Without runtime dependency:
```
(ns ... (:require [typed.clojure :as-alias t])) ;; DON'T load typed.clojure
(ns ... (:require [typed.clojure :as-alias t])) ;; DON'T load typed.clojure
(... (fn [^{::t/- t/Int} a]) ...)
```
Put another way, check out the deps.edn of my malli fork: Typed Clojure is a test dependency, not a runtime dependency! https://github.com/frenchy64/malli/pull/1/files
This release also contains a bugfix for the malli->type translation, reported by paola pereira in Clojurians Slack #core-typed. I adding a new example namespace based on their report that shows how to use malli's global registries with Typed Clojure: https://github.com/typedclojure/typedclojure/blob/main/example-projects/malli-type-providers/src/typed_example/malli_global_registry.cljc
Check out the changelog for full list of improvements https://github.com/typedclojure/typedclojure/blob/main/CHANGELOG.md#1027
Thanks,
Ambrose
Ambrose