Reproduction Steps
Open a new place, copy/paste this source into a script.
Source Code
--!strict
local n: (number|string) & (number|string) = 5;
--[[
Type Error: (13,1) Type '(number | string) & (number | string)'
could not be converted into 'number | string';
none of the union options are compatible
(spacing mine)
--]]
local m: (number|string) = n;
This is a pared down example. To be honest, I’m not entirely sure how I got into this situation. I was working with some code that I wrote when I was first getting the hang of Luau, so there might be some wonkiness there. Still, it seems that types of form (X|Y)&(X|Y)
should be convertible to (X|Y)
Expected Behavior
I expect type (number|string)&(number|string)
to be convertable to type (number|string)
.
Actual Behavior
I get a typechecking error.
Workaround
As always, the :: any
escape hatch.
Issue Area: Studio
Issue Type: Other
Impact: Moderate
Frequency: Very Rarely