Issue Type: Other
Impact: Low
Frequency: Constantly
Date First Experienced: 2021-04-25 17:04:00 (-07:00)
Date Last Experienced: 2021-04-25 18:04:00 (-07:00)
Reproduction Steps:
type T = {
x: number
};
type U = T & {
y: number
};
function f(a: U)
print(a.x);
a.x = 5 -- error
end
Above shows that attempting to write to an intersected type makes the checker shout at the user; despite the given type intersecting T. Reading shows no issue, however.
It doesn’t matter whether the type being intersected is empty, the checker will still throw:
type T = {};
type U = T & {
x: number,
y: number
};
function f(a: U)
print(a.x);
a.x = 5 -- error
end
Expected Behavior:
The script should be clear from any underlines - regardless of my U
type not having an explicitly-defined x
field.
Actual Behavior:
Writing to a.x
makes the checker respond with something among the lines of Expected type table, got 'T & {| y: number |}' instead
.
In the editor:
Workaround:
Don’t use type intersection and instead define your fields all in one type. This isn’t a very great workaround.