Skip to content

Way to @type annotate array of functions without { [integer]: fun() } #2367

Description

@d-enk
---@type { v: integer }[]
_ = {
	{ v = "" }, --- b: integer - Cannot assign `string` to `integer`.
}

---@type { [integer]: fun(v: integer) }
_ = {
	[2] = function(v)
		_ = v --- b: integer
	end,

	function(v)
		_ = v --- b: any ???
	end,
}


---@type fun(v: integer)[]
_ = {
	[2] = function(v)
		_ = v --- b: any
	end,

	function(v)
		_ = v --- v: any ???
	end,
}

I wish the last option would work, or at least without [2] in { [integer]: fun() }

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions