Type-checking question here: what is the proper way to write a nullable / optional tuple?
Ex.:
-- Returns the nearest player to `part` and the distance between them,
-- IF there is a player's character
local function getNearestPlayer(part: Part)
local nearestPlayer = nil
local smallestDistance = math.huge
-- algorithm for finding the nearest player...
-- finished.
-- at this point, if no players were found, `nearestPlayer` remains nil
-- and `smallestDistance` is still `math.huge`
-- so the function's return should be either the tuple `(Player, number)`
-- or `nil`.
-- ideally, I should be able to do `(Player, number)?` or maybe
-- `(Player, number) | nil`, but the closest I can find is `(Player?, number?)`
-- but there's some obvious issues.
end
This feels more like a feature request, but whatever. Just in case somebody faces the same little issue (or for future me).