Lua typechecker
See original GitHub issueType checkers are a great tool to improve robustness of code written. It would be great to add some kind of type-checking capabilities to EmmyLua where the types of arguments are matched with the expected types as defined in their definition. This would also include checking if returned values match the specified return types.
This could be a plugin setting that could be enabled or not, and when enabled shows either an error or a warning whenever a type missmatch occurs, and would require the types of each function to be declared. I envision this working similar to TypeScript’s type system.
For example:
--- @type myEnum
ENUM_VAL = 1
--- @param enum myEnum
--- @return number
function myFunction(enum)
return "2" -- ERROR: Return type (string) does not match specified type (number)
end
myFunction(3) -- ERROR: Parameter 1' type (int) does not match expected type (myEnum)
I don’t know if this is something that is on the agenda or how hard this would be to include in the plugin, but I think including this functionality would be great.
PS: I am more than willing to share my knowledge on the subject if needed.
Issue Analytics
- State:
- Created 6 years ago
- Reactions:2
- Comments:11 (8 by maintainers)
Top GitHub Comments
@tangzx
Has a ton of issues rn such as some things evaluating as TyLazyClass and nil evaluating as any. Also argument number checking is a bad idea since a lot of functions even in standard lib have optional args 😦
Argument number could still be enforced with some function flag
The code is simple right now:
See #59