The core.specs.alpha library has been ported to ClojureScript, and is available in this release as an opt-in feature. This library contains specs that describes core macros and functions. Support for the ns
special form is additionally included.
To use this library, simply require the new cljs.core.specs.alpha
namespace. By doing this, specs for defn
, let
, and other macros will be registered, and subsequent compilation of these macros will be subject to spec validation.
The following illustrates its use at the REPL. Let's say you accidentally attempt to refer all symbols of a library, using a Clojure-specific feature that does not exist in ClojureScript:
cljs.user=> (require '[clojure.set :refer :all])
clojure.lang.ExceptionInfo: Don't know how to create ISeq from: clojure.lang.Keyword at line 1 ...
This error is a bit cryptic. Now, let's try again, but using core.specs.alpha
:
cljs.user=> (require 'cljs.core.specs.alpha)
nil
cljs.user=> (require '[clojure.set :refer :all])
clojure.lang.ExceptionInfo: Call to cljs.core/require did not conform to spec:
In: [0 1 :refer] val: :all fails spec: :cljs.core.specs.alpha/refer at:
[:args :spec :libspec :lib+opts :options :refer] predicate: coll?
...
The resulting error is essentially indicating that :refer
takes a collection as its argument.
This feature is still alpha, but we encourage you to give it a try and report any defects you might find!