### Define a function with a type error Source: https://typedclojure.org/guides/getting_started Example of code that will trigger a type error when checked. ```clojure (ns org.my-domain.my-project (:require [typed.clojure :as t])) (t/ann welcome-string [t/Str :-> t/Str]) (defn welcome-string [a-name] (str "Welcome, " a-name)) (welcome-string nil) ``` -------------------------------- ### Create a new project Source: https://typedclojure.org/guides/getting_started Initialize a new project using Leiningen. ```bash $ lein new org.my-domain/my-project $ cd my-project ``` -------------------------------- ### Configure project.clj Source: https://typedclojure.org/guides/getting_started Add Typed Clojure dependencies to your project configuration file. ```clojure (defproject org.my-domain/my-project "0.1.0-SNAPSHOT" :dependencies [[org.clojure/clojure "1.11.1"] ;; annotation macros like t/ann [org.typedclojure/typed.clj.runtime "1.1.5"]] :profiles {:dev {:dependencies [;; the full type checker, only needed at dev-time [org.typedclojure/typed.clj.checker "1.1.5"]]}} :repl-options {:init-ns org.my-domain.my-project}) ``` -------------------------------- ### Run the type checker Source: https://typedclojure.org/guides/getting_started Execute the type checker within a running REPL session. ```bash $ lein repl Clojure 1.11.1 org.my-domain.my-project=> (t/check-ns-clj) Start checking org.my-domain.my-project Checked org.my-domain.my-project in 32.836713 msecs :ok ``` -------------------------------- ### Inspect type documentation Source: https://typedclojure.org/guides/getting_started Use the doc-clj function to retrieve information about specific types. ```clojure org.my-domain.my-project=> (t/doc-clj t/U) Special type: typed.clojure/U U represents a union of types Forms: [(U type*)] nil org.my-domain.my-project=> (t/doc-clj t/Str) Type alias typed.clojure/Str String Metadata: {:doc "A string", :forms '[Str], :file "typed/ann/clojure.cljc"} nil ``` -------------------------------- ### Annotate and define a function Source: https://typedclojure.org/guides/getting_started Define a function with explicit type annotations for arguments and return values. ```clojure (ns org.my-domain.my-project (:require [typed.clojure :as t])) (t/ann welcome-string [t/Str :-> t/Str]) (defn welcome-string [a-name] (str "Welcome to " a-name "!")) (welcome-string "Typed Clojure") ;=> "Welcome to Typed Clojure!" ``` -------------------------------- ### View type error output Source: https://typedclojure.org/guides/getting_started The output displayed in the REPL when a type mismatch is detected. ```text org.my-domain.my-project=> (t/check-ns-clj) Start checking org.my-domain.my-project Type Error (file:/Users/ambrose/Projects/typedclojure.org/example-projects/my-project/src/org/my_domain/my_project.clj:10:1) Function welcome-string could not be applied to arguments: Domains: t/Str Arguments: nil Ranges: t/Str in: (welcome-string nil) Execution error (ExceptionInfo) at clojure.core.typed.errors/print-errors! (errors.cljc:274). Type Checker: Found 1 error ``` -------------------------------- ### Verify successful type check Source: https://typedclojure.org/guides/getting_started Confirm the namespace passes type checking after updating annotations. ```clojure org.my-domain.my-project=> (t/check-ns-clj) Start checking org.my-domain.my-project Checked org.my-domain.my-project in 32.831593 msecs :ok ``` -------------------------------- ### Update type annotation for nil Source: https://typedclojure.org/guides/getting_started Modify the annotation to allow nil values using a union type. ```clojure (t/ann welcome-string [(t/U nil t/Str) :-> t/Str]) ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.