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

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

A poor man’s nonnothingtype:

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
  2. Base.nonmissingtype and Core.Compiler.typesubtract aren't exported
  3. Dispatch using Union and order of arguments