Optional TaggedUnions not refining to correct type when if validation is present

From what I discovered the type solver just freaks out and evaluates to one of the types in the union when if validation is present.

Working Example (Union is not optional)

Source:

--!strict
type Type1 = {
	Type: "Type1",
	CommonKey: string,
	Type1Key: string,
}
type Type2 = {
	Type: "Type2",
	CommonKey: string,
	Type2Key: string,
}
type UnionType = Type1 | Type2

local foo: UnionType = nil
if foo.Type == "Type2" then
	foo.
end

Not Working Example (Union is optional)

Source:

--!strict
type Type1 = {
	Type: "Type1",
	CommonKey: string,
	Type1Key: string,
}
type Type2 = {
	Type: "Type2",
	CommonKey: string,
	Type2Key: string,
}
type UnionType = Type1 | Type2

local foo: UnionType? = nil
if foo then
	if foo.Type == "Type2" then
		foo.
	end
end

MORE INFO:

  • Tried both the new and the old solver. They both fail
  • Uninstalled all plugins before testing.
  • No significant beta feature related to type solver other than New Typesolver
  • Using latest build of roblox studio as of posting this

Expected behavior

Expected behaviour should be type still getting correctly refined.

Hello! Thank you for the report and for beta testing the new type solver. This looks like a pretty strange issue, but I am able to reproduce the issue from your second example so we’ll take a look. We’ll try to keep you in the loop on any updates here.

1 Like

Just closing the loop here: the fix for this should have gone out some time ago! Please reach out if you encounter any further issues.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.