How to return a placeholder value in Hack?

Viewed 82

I am implementing a function that returns an Awaitable<T>- but for the moment, I just want to return a placeholder value.

How do I accomplish this?

In rust, I'd so something like invoke the unimplemented!() macro - in java/python, I'd return null or raise an exception

1 Answers

Control that always reaches an exception is a bottom type, so you can raise an exception to get any type:

function unimplemented<T>(): T {
  throw new Exception("Unimplemented!");
}

If you want a usable placeholder value at runtime from your function, your only option is indeed null and a bunch of nullable annotations.

Related