luau
luau copied to clipboard
Optional field in generic table types rejects table literal due to invariant property check
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