Skip to content

Include fields with their types in the return type annotation when it's a table with known fields#1

Open
anaissls wants to merge 1 commit into
NyakoFox:mainfrom
anaissls:main
Open

Include fields with their types in the return type annotation when it's a table with known fields#1
anaissls wants to merge 1 commit into
NyakoFox:mainfrom
anaissls:main

Conversation

@anaissls

@anaissls anaissls commented Nov 2, 2025

Copy link
Copy Markdown

There are a few functions that return a table with known fields, such as love.filesystem.getInfo(), which in the love api, its return type is a table with the following fields and types: {type:FileType, size:number, modtime:number}.

However, in these cases, the return type is generated as table, with no hints about the fields it has.

This small modification changes the return type in these cases, replacing it with an annotation that includes the fields and its types as defined in the love api:

-- Before
---@return table
---@overload fun(path:string, info:table):table
---@overload fun(path:string, filtertype:FileType?):table
function love.filesystem.getInfo(path, filtertype, info) end

-- After
---@return {type:FileType, size:number, modtime:number}
---@overload fun(path:string, info:table):{type:FileType, size:number, modtime:number}
---@overload fun(path:string, filtertype:FileType?):{type:FileType, size:number, modtime:number}
function love.filesystem.getInfo(path, filtertype, info) end

There are seven of such cases (not including function overloads).

Found the change easy to implement, so I wanted to contribute to this EmmyLua love annotations fork, which seems to be the most up to date.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant