Fork me on GitHub
#core-typed
<
2022-03-31
>
emccue03:03:23

I'm a little confused on how any works

emccue03:03:38

(t/ann x t/Any)
(def x ",")

(t/ann y t/Any)
(def y ["a"])

(string/join x y)
(comment
  (t/check-ns-clj))

emccue03:03:40

This code fails with

Type Error (file:/Users/emccue/Development/tyyyyyped/src/tyt.clj:12:1) 
Function string/join could not be applied to arguments:


Domains:
	t/Any (t/Seqable t/Any)

Arguments:
	t/Any t/Any

Ranges:
	t/Str




in:
(string/join x y)



Execution error (ExceptionInfo) at clojure.core.typed.errors/print-errors! (errors.cljc:273).
Type Checker: Found 1 error
on type checking - which means that t/Any doesn't satisfy (t/Seqable t/Any), which confuses me some

ambrosebs22:03:28

s/Any cannot be passed as a (t/Seqable t/Any). But (t/Seqable t/Any) can be passed as t/Any .

ambrosebs22:03:43

With the current annotation for y, you could have (def y :kw) which is not a (t/Seqable t/Any)

ambrosebs22:03:51

if it helps, t/Any is more like Object in Java, and is nothing like any in TypeScript

ambrosebs22:03:33

it's (only) the top of the type hierarchy (TS's any is also the bottom).

emccue23:03:46

is there a bottom type? (never or such)

ambrosebs00:04:52

t/Nothing aka (t/U)

ambrosebs00:04:48

if you need an escape hatch like any, there are a few options. 1. (t/ann ^:no-check foo ...) ignores the definition of vars 2. clojure.core.typed.unsafe/ignore-with-unchecked-cast casts a form to any type. There'll probably be more ways in the future.

ambrosebs00:04:45

You can also wrap forms in (t/tc-ignore ..) to completely skip them. I think the best balance is ^:no-check + t/tc-ignore atm.

ambrosebs00:04:35

But one of the things that has made typed clojure still interesting to me after all these years was avoiding an any type, so this is the state of things 🙂

ambrosebs00:04:05

the discoverability is very low on this stuff so feel free to keep asking

emccue03:04:08

yeah - so long as this slack keeps history you can maybe use it for copy pasting into a wiki