Internal functions for CLJS
Internal functions for CLJS
(ann varsym typesyn)
Annotate varsym with type. If unqualified, qualify in the current namespace. If varsym has metadata {:no-check true}, ignore definitions of varsym while type checking.
eg. ; annotate the var foo in this namespace (ann foo [Number -> Number])
; annotate a var in another namespace (ann another.ns/bar [-> nil])
; don't check this var (ann ^:no-check foobar [Integer -> String])
Annotate varsym with type. If unqualified, qualify in the current namespace. If varsym has metadata {:no-check true}, ignore definitions of varsym while type checking. eg. ; annotate the var foo in this namespace (ann foo [Number -> Number]) ; annotate a var in another namespace (ann another.ns/bar [-> nil]) ; don't check this var (ann ^:no-check foobar [Integer -> String])
(ann-datatype & args)
Annotate datatype Class name dname with expected fields. If unqualified, qualify in the current namespace.
eg. (ann-datatype MyDatatype [a :- Number, b :- Long])
(ann-datatype another.ns.TheirDatatype [str :- String, vec :- (IPersistentVector Number)])
Annotate datatype Class name dname with expected fields. If unqualified, qualify in the current namespace. eg. (ann-datatype MyDatatype [a :- Number, b :- Long]) (ann-datatype another.ns.TheirDatatype [str :- String, vec :- (IPersistentVector Number)])
(ann-form form ty)
Annotate a form with an expected type.
Annotate a form with an expected type.
(ann-jsnominal varsym jsnom)
Equivalent of TypeScript interface
Equivalent of TypeScript interface
(ann-protocol & args)
Annotate a possibly polymorphic protocol var with method types.
eg. (ann-protocol IFoo bar [IFoo -> Any] baz [IFoo -> Number])
; polymorphic
(ann-protocol [[x :variance :covariant]]
IFoo
bar
[IFoo -> Any]
baz
[IFoo -> Number])
Annotate a possibly polymorphic protocol var with method types. eg. (ann-protocol IFoo bar [IFoo -> Any] baz [IFoo -> Number]) ; polymorphic (ann-protocol [[x :variance :covariant]] IFoo bar [IFoo -> Any] baz [IFoo -> Number])
(atom & args)
Like atom, but with optional type annotations.
Same as (atom (ann-form init t) args*)
eg. (atom 1) : (Atom (Value 1)) (atom :- Num, 1) : (Atom Num)
Like atom, but with optional type annotations. Same as (atom (ann-form init t) args*) eg. (atom 1) : (Atom (Value 1)) (atom :- Num, 1) : (Atom Num)
(cf form)
(cf form expected)
Check a single form with an optional expected type.
Check a single form with an optional expected type.
(check-ns)
(check-ns ns-or-syms)
Check a Clojurescript namespace, or the current namespace with zero args. This macro is intended to be called at the Clojurescript REPL with a subset of clojure.core.typed/check-ns's features.
For the equivalent function (callable from Clojure only) see cljs.core.typed/check-ns*.
Check a Clojurescript namespace, or the current namespace with zero args. This macro is intended to be called at the Clojurescript REPL with a subset of clojure.core.typed/check-ns's features. For the equivalent function (callable from Clojure only) see cljs.core.typed/check-ns*.
(def name & fdecl)
Like clojure.core/def with optional type annotations. Registers annotations like t/ann.
NB: in Clojure it not useful refer a macro called def
as it is a
special form. Use an alias prefix (eg., t/def
).
eg. ;same as clojure.core/def (def vname 1)
;with Number `ann`
(def vname :- Number 1)
;doc
(def vname
"Docstring"
:- Long
1)
Like clojure.core/def with optional type annotations. Registers annotations like t/ann. NB: in Clojure it not useful refer a macro called `def` as it is a special form. Use an alias prefix (eg., `t/def`). eg. ;same as clojure.core/def (def vname 1) ;with Number `ann` (def vname :- Number 1) ;doc (def vname "Docstring" :- Long 1)
(defalias sym t)
(defalias sym doc-str t)
Define a type alias. Takes an optional doc-string as a second argument.
Updates the corresponding var with documentation.
eg. (defalias MyAlias "Here is my alias" (U nil String))
Define a type alias. Takes an optional doc-string as a second argument. Updates the corresponding var with documentation. eg. (defalias MyAlias "Here is my alias" (U nil String))
(defn & args)
Like defn, but registers annotation with t/ann.
eg. (defn fname [a :- Number, b :- (U Symbol nil)] :- Integer ...)
;annotate return (defn fname [a :- String] :- String ...)
;multi-arity (defn fname ([a :- String] :- String ...) ([a :- String, b :- Number] :- Long ...))
;polymorphic function (defn :forall [x y] fname ([a :- x] :- (Coll y) ...) ([a :- Str, b :- y] :- y ...))
Like defn, but registers annotation with t/ann. eg. (defn fname [a :- Number, b :- (U Symbol nil)] :- Integer ...) ;annotate return (defn fname [a :- String] :- String ...) ;multi-arity (defn fname ([a :- String] :- String ...) ([a :- String, b :- Number] :- Long ...)) ;polymorphic function (defn :forall [x y] fname ([a :- x] :- (Coll y) ...) ([a :- Str, b :- y] :- y ...))
(defprotocol & body)
Like defprotocol, but with optional type annotations.
Omitted annotations default to Any. The first argument of a protocol cannot be annotated.
Add a binder before the protocol name to define a polymorphic protocol. A binder before the method name defines a polymorphic method, however a method binder must not shadow type variables introduced by a protocol binder.
Return types for each method arity can be annotated.
Unlike clojure.core/defprotocol, successive methods can have the same arity. Semantically, providing multiple successive methods of the same arity is the same as just providing the left-most method. However the types for these methods will be accumulated into a Fn type.
eg. ;annotate single method (defprotocol MyProtocol (a [this a :- Integer] :- Number))
;polymorphic protocol (defprotocol [[x :variance :covariant]] MyProtocol (a [this a :- Integer] :- Number))
;multiple types for the same method (defprotocol [[x :variance :covariant]] MyProtocol (a [this a :- Integer] :- Integer [this a :- Long] :- Long [this a :- Number] :- Number))
;polymorphic method+protocol (defprotocol [[x :variance :covariant]] MyProtocol ([y] a [this a :- x, b :- y] :- y))
Like defprotocol, but with optional type annotations. Omitted annotations default to Any. The first argument of a protocol cannot be annotated. Add a binder before the protocol name to define a polymorphic protocol. A binder before the method name defines a polymorphic method, however a method binder must not shadow type variables introduced by a protocol binder. Return types for each method arity can be annotated. Unlike clojure.core/defprotocol, successive methods can have the same arity. Semantically, providing multiple successive methods of the same arity is the same as just providing the left-most method. However the types for these methods will be accumulated into a Fn type. eg. ;annotate single method (defprotocol MyProtocol (a [this a :- Integer] :- Number)) ;polymorphic protocol (defprotocol [[x :variance :covariant]] MyProtocol (a [this a :- Integer] :- Number)) ;multiple types for the same method (defprotocol [[x :variance :covariant]] MyProtocol (a [this a :- Integer] :- Integer [this a :- Long] :- Long [this a :- Number] :- Number)) ;polymorphic method+protocol (defprotocol [[x :variance :covariant]] MyProtocol ([y] a [this a :- x, b :- y] :- y))
(fn & forms)
Like clojure.core/fn, but with optional annotations.
eg. ;these forms are equivalent (fn [a] b) (fn [a :- Any] b) (fn [a :- Any] :- Any b) (fn [a] :- Any b)
;annotate return
(fn [a :- String] :- String body)
;named fn
(fn fname [a :- String] :- String body)
;rest parameter
(fn [a :- String & b :- Number *] body)
;dotted rest parameter
(fn [a :- String & b :- Number ... x] body)
;multi-arity
(fn fname
([a :- String] :- String ...)
([a :- String, b :- Number] :- String ...))
; polymorphic binder
(fn :forall [x y z]
fname
([a :- String] :- String ...)
([a :- String, b :- Number] :- String ...))
Like clojure.core/fn, but with optional annotations. eg. ;these forms are equivalent (fn [a] b) (fn [a :- Any] b) (fn [a :- Any] :- Any b) (fn [a] :- Any b) ;annotate return (fn [a :- String] :- String body) ;named fn (fn fname [a :- String] :- String body) ;rest parameter (fn [a :- String & b :- Number *] body) ;dotted rest parameter (fn [a :- String & b :- Number ... x] body) ;multi-arity (fn fname ([a :- String] :- String ...) ([a :- String, b :- Number] :- String ...)) ; polymorphic binder (fn :forall [x y z] fname ([a :- String] :- String ...) ([a :- String, b :- Number] :- String ...))
(inst inst-of & types)
Instantiate a polymorphic type with a number of types
Instantiate a polymorphic type with a number of types
(let bvec & forms)
Like clojure.core/let but supports optional type annotations.
eg. (let [a :- Type, b a2 1.2] body)
Like clojure.core/let but supports optional type annotations. eg. (let [a :- Type, b a2 1.2] body)
(letfn> fn-specs-and-annotations & body)
Like letfn, but each function spec must be annotated.
eg. (letfn> [a :- [Number -> Number] (a [b] 2)
c :- [Symbol -> nil]
(c [s] nil)]
...)
Like letfn, but each function spec must be annotated. eg. (letfn> [a :- [Number -> Number] (a [b] 2) c :- [Symbol -> nil] (c [s] nil)] ...)
(loop bindings & exprs)
Like clojure.core/loop, and supports optional type annotations. Arguments default to a generalised type based on the initial value.
eg. (loop [a :- Number 1 b :- (U nil Number) nil] ...)
Like clojure.core/loop, and supports optional type annotations. Arguments default to a generalised type based on the initial value. eg. (loop [a :- Number 1 b :- (U nil Number) nil] ...)
(tc-ignore & body)
Ignore forms in body during type checking
Ignore forms in body during type checking
cljdoc is a website building & hosting documentation for Clojure/Script libraries
× close