Skip to content

Wrong type resolution when inheriting array class #999

@Silzinc

Description

@Silzinc

Hi, I have the following snippet:

---@class Foo
---@field [integer] string
---@field other number
local f = {}

---@param array string[]
local function bar(array)
  print(array[1])
end

---@param foo Foo?
local function baz(foo)
  foo = foo or { other = 5 } --[[@as Foo]]
  bar(foo)
end

baz(f)

This is fine so far, but dropping --[[@as Foo]] introduces a warning because foo is not resolved as Foo anymore and thus not as a valid string[]. Is this a design choice or would it be possible to have the right type resolution without the explicit comment? Thank yon in advance!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions