union types in combination with a function gives incorrect warning

local str: "state1" | "state2" = "state1"

local function ObserveState() :number
	if str == "state1" then
		return 1
	elseif str == "state2" then
		return 2
	end
	-- "Not all codepaths in this function return 'number'"
end

str can ONLY be state1 or state2, so the typechecker should be smart enough to know that nothing needs to be returned outside of the if statement

1 Like

Is this on the beta type checker?

i wish i could just say “no it is not” but there is a character limit which is why i am typing out this message.

Thanks for reporting! This looks more like a feature request for exhaustivity checking which should be shared in the Feature Requests category.