I’m sure you guys love hearing about issues with the type checker so here I am yet again.
Intersections and type assertions do not play well with each other whatsoever. Trying to coerce something into a type that happens to be an intersection just straight up fails even though the coercion is completely valid. Here’s an example of that:
type XVector = {x: number}
type YVector = {y: number}
type Vector2 = XVector & YVector
local a: Vector2 = { --perfectly fine
x = 0,
y = 0
}
local b = { --Error: Type 'XVector & YVector' could not be converted into {x: any, y:any}
x = 0,
y = 0
} :: Vector2
Note that the TypeScript equivalent to the code above produces no errors and b
is correctly typed as Vector2
On a side note, its great to see table types getting some love this time around. Arrays with union types erroring out for no reason has been a long standing issue and I’m glad to see the effort being put in. I’m also curious about an ETA for the re-release of generic functions? Ever since they got reverted I haven’t seen much about them and they would be extremely useful.