type a = {
m: {
c: number
};
}
type b = {
m: {
c: number;
d: number?;
}
}
-- Cannot cast 'a' into 'b' because the types are unrelated
local v = ((nil :: any) :: a) :: b
Yes this simpler case without nested tables works fine:
type a = {
c: number
}
type b = {
c: number;
d: number?;
}
-- This is okay
local v = ((nil :: any) :: a) :: b
Hey there, just wanted to follow-up with an update on this issue! The Luau team is currently hard at work on implementing an approach called local type inference that will allow us to get more accurate typechecking in situations like this. This work is still ongoing, but I wanted to at least let you know that this issue (and really, a whole host of similar restrictions to Luau’s current typechecker) are being worked on and will hopefully be fixed in an upcoming release!