# How to get the non-Nothing type from \`Union{T,Nothing}\`

**URL:** <https://discourse.julialang.org/t/how-to-get-the-non-nothing-type-from-union-t-nothing/30523>\
**Category:** General Usage\
**Tags:** question\
**Created:** [October 31, 2019, 7:03am UTC](https://discourse.julialang.org/t/how-to-get-the-non-nothing-type-from-union-t-nothing/30523 "2019-10-31T07:03:26Z")\
**Posts on this page:** 1\
**Showing post:** 3

<div class="post-metadata">

**Author:** ![singularitti](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/singularitti/32/17678_2.png) [@singularitti](https://discourse.julialang.org/u/singularitti)\
**Post date:** [October 31, 2019, 7:23am UTC](https://discourse.julialang.org/t/how-to-get-the-non-nothing-type-from-union-t-nothing/30523/3 "2019-10-31T07:23:18Z")

</div>

Hmmm. It is the first time I heard about this function. It uses `Core.Compiler.typesubtract`. Thank you.

A poor man’s `nonnothingtype`:

```julia
nonnothingtype(::Type{T}) where {T} = Core.Compiler.typesubtract(T, Nothing)

```

I did a little bit search and found some links, hope this would help others:

1. [Get non-missing type in the case of parametric type](https://discourse.julialang.org/t/get-non-missing-type-in-the-case-of-parametric-type/29109)
2. [Base.nonmissingtype and Core.Compiler.typesubtract aren't exported](https://discourse.julialang.org/t/base-nonmissingtype-and-core-compiler-typesubtract-arent-exported/24367)
3. [Dispatch using Union and order of arguments](https://discourse.julialang.org/t/dispatch-using-union-and-order-of-arguments/19732)

---

_[View the full topic](https://discourse.julialang.org/t/how-to-get-the-non-nothing-type-from-union-t-nothing/30523)._
