core.typed - Trying to annotate a Record in dependency

99 views Asked by At

I'm trying to annotate the Element record in clojure.data.xml which is:

(defrecord Element [tag attrs content])

I've annotated it as follows:

(t/ann-record Element [tag :- t/Keyword  attrs :- (t/HMap :complete? false)
                                    content :- (t/Vec Element)])

And I have the following function which doesn't type check:

(t/ann get-content [Element -> (t/Vec Element)]) (defn get-content [xml] (:content xml))

with 'Expected: t/Vec clojure.data.xml.Element Actual: t/Any'

I've also tried replacing that with (get xml :content) but it fails with the same output. I wonder what I'm doing wrong :D

1

There are 1 answers

0
overthink On

It might be that you need to fully qualify Element in your ann-record call (I'm assuming your code is not actually in the clojure.data.xml namespace).

The docs for ann-record say

...
; a record in another namespace
(ann-record another.ns.TheirRecord
              [str :- String,
               vec :- (Vec Number)])
...

So in this particular case:

(t/ann-record clojure.data.xml.Element
  [tag :- t/Keyword  
   attrs :- (t/HMap :complete? false) 
   content :- (t/Vec Element)])