core-typed

2025-12-15T13:06:19.294739Z

Hi, what’s the correct way to require a defalias “var” from another namespace?

2025-12-15T15:16:21.118479Z

You need to ensure the defalias itself is loaded by the time the type checker runs in order of the type checker to find it. In terms of referring to it, you can use a fully qualified ns or a ns alias.

(require '[foo.bar :as-alias f])
(defalias Something f/Bar)

2025-12-15T15:16:55.927249Z

there's no way to refer it into the current ns. it's similar to spec s/def in this this way.

2025-12-15T15:18:56.100479Z

I see, So just to clarify, to import a defalias, we need to use the as-alias in our require statement? I attempted to just use :as and that does not seem to work.

2025-12-15T15:20:56.448329Z

:as should work too

2025-12-15T15:22:10.381159Z

This uses the same mechanism (require '[typed.clojure :as t]) => t/Seqable

2025-12-15T15:24:07.585629Z

okay, cool! I will check it out. I must have done something wrong on my side then.

2025-12-15T15:27:17.134769Z

fwiw even though it's a static type checker the type checker relies on the dynamic state of the repl to pick up the annotation, similar to spec. it's not enough to just save the file containig the defalias, it needs to be evaled.

2025-12-15T15:34:03.519109Z

Got it. I am using clj-reload to reload clojure namespaces.

👍 1
2025-12-15T15:38:35.467549Z

there's some cleverness behind the scenes so that defaliases can be removed automatically on reload if they are deleted in source. I think it should be compatible with clj-reload, I designed it for tools.namespace. Effectively the alias expires if the Namespace object that originally registered it is gc'ed.

2025-12-15T15:43:42.538249Z

Okay, very cool.