# Is there a reason why typeintersect constrains the args using type assertions in the method body instead of using dispatch?

**URL:** https://discourse.julialang.org/t/is-there-a-reason-why-typeintersect-constrains-the-args-using-type-assertions-in-the-method-body-instead-of-using-dispatch/118102
**Category:** Internals & Design
**Tags:** question, type
**Created:** [August 12, 2024, 4:49pm UTC](https://discourse.julialang.org/t/is-there-a-reason-why-typeintersect-constrains-the-args-using-type-assertions-in-the-method-body-instead-of-using-dispatch/118102 "2024-08-12T16:49:58Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![nsajko](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nsajko/32/221187_2.png) [@nsajko](https://discourse.julialang.org/u/nsajko)
#### Post date: [August 12, 2024, 4:49pm UTC](https://discourse.julialang.org/t/is-there-a-reason-why-typeintersect-constrains-the-args-using-type-assertions-in-the-method-body-instead-of-using-dispatch/118102/1 "2024-08-12T16:49:58Z")

</div>

This is the definition of `typeintersect`:

> <https://github.com/JuliaLang/julia/blob/a23aee8c66aaf2c2b35ecb63fe938ae8519f49d9/base/reflection.jl#L931-L931>

> ```julia
> typeintersect(@nospecialize(a), @nospecialize(b)) = (@_total_meta; ccall(:jl_type_intersection, Any, (Any, Any), a::Type, b::Type))
> 
> ```

It seems like the following would be an improvement, because an exception would be thrown sooner when any of the two arguments isn’t a `Type`:

```julia
typeintersect(@nospecialize(a::Type), @nospecialize(b::Type)) = (@_total_meta; ccall(:jl_type_intersection, Any, (Any, Any), a, b))

```

Is this just because of backwards compatibility and the distinction between `TypeError` and `MethodError`? Or maybe it’s some kind of bootstrapping-related limitation?
