luau icon indicating copy to clipboard operation
luau copied to clipboard

Optional field in generic table types rejects table literal due to invariant property check

Open Waffle3z opened this issue 3 months ago • 0 comments

Repro:

type A<T> = {
    s: T,
    n: number?,
}
local function f<T>(_a: A<T>)
    return
end
f({ s = "hello", n = 1 }) -- TypeError: Type 'number' could not be converted into 'nil' in an invariant context

does not error if the table type is not generic:

type B = {
    s: string,
    n: number?,
}
local function g(_b: B)
    return
end
g({ s = "hello", n = 1 }) -- no type error

Waffle3z avatar Sep 02 '25 20:09 Waffle3z