module T
def self.must_because(arg)
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 "reason_foo_should_not_be_nil" if foo.nil?
foo = maybe_gives_foo
Equivalent to:
needs_foo(T.must_because(maybe_gives_foo) {"reason_foo_should_not_be_nil"})
Intended to be used as:
is `nil` and return it otherwise.
A convenience method to `raise` with a provided error reason when the argument
def self.must_because(arg) return arg if arg return arg if arg == false begin raise TypeError.new("Unexpected `nil` because #{yield}") rescue TypeError => e # raise into rescue to ensure e.backtrace is populated T::Configuration.inline_type_error_handler(e, {kind: 'T.must_because', value: arg, type: nil}) end end