Skip to content

Add type annotations to all functions and fields of modutil #16

@alexmaichen

Description

@alexmaichen

Most code-editors provide a type-checker for the most common languages. Static type-checking guarantees the program will never crash from lack of type-safety.
Due to being an interpreted dynamically typed language, Lua's typechecker isn't very good on its own. One can help it by adding special comments before variable or function declarations to tell it what the expected value-type in that spot is. If there is a type mismatch between the expected and the provided, the typechecker will show an error (or in the case of lua's typechecker, a warning)

Documentation about annotations found here https://luals.github.io/wiki/annotations/
The main 3 notations to keep in mind would be:

-- variables
---@type variablename type
-- tables
---@type tablevariablename table<keytype, valuetype>
-- functions (to avoid the rather verbose `---@param name type` and `---@return name type` alternative)
---@type fun(param1: type1, param2: type2, param3: type3, ...): returntype

Unfortunately, I cannot find an example of a mod that uses type hints to justify this by precedent, and the game doesn't either; would be nice to have though.

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