Skip to content

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

@Waffle3z

Description

@Waffle3z

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions