module T

def self.must(arg, msg=nil)

sig {params(arg: T.nilable(A), msg: T.nilable(String)).returns(A)}

to contain a non-nil value at this point.
Intended to be used to promise sorbet that a given nilable value happens

needs_foo(foo)
raise "nil" if foo.nil?
foo = maybe_gives_foo

Equivalent to:

needs_foo(T.must(maybe_gives_foo))

Intended to be used as:

otherwise.
A convenience method to `raise` when the argument is `nil` and return it
def self.must(arg, msg=nil)
  return arg if arg
  return arg if arg == false
  begin
    if msg
      if !T.unsafe(msg).is_a?(String)
        raise TypeError.new("T.must expects a string as second argument")
      end
    else
      msg = "Passed `nil` into T.must"
    end
    raise TypeError.new(msg)
  rescue TypeError => e # raise into rescue to ensure e.backtrace is populated
    T::Private::ErrorHandler.handle_inline_type_error(e)
  end
end