Automatically generate Lua type definitions for your FiveM/RedM server resource exports. This tool scans your server files and creates IntelliSense type definitions for resource exports, Cfx GlobalState, LocalPlayer and Player state variables, giving you autocomplete and type checking in VS Code.
- Automatically scans all Lua files in your FiveM/RedM server
- Parses LuaDoc comments (
---@param,---@return, etc.) - Detects both function-based and inline exports
- Separates client, server, and shared exports
- Generates type definitions for GlobalState variables
- Generates type definitions for Player and LocalPlayer state bags
- Configurable via JSON config file
npm install- Configure
inputDirto your server path - Run the type generator:
npm startThis will scan all Lua files and generate type definitions in the ./types directory.
Edit the config.json file in your project root:
{
"inputDir": "./server",
"outputDir": "./types",
"excludePatterns": [
"node_modules/**",
"types/**"
],
"verbose": false
}- inputDir: Directory to scan for Lua files (normally your server resources folder)
- outputDir: Where to output generated type files
- excludePatterns: Glob patterns to exclude from scanning
- verbose: Show detailed output during generation
Now that we generated the types, we need to add them to your VS Code settings:
- Install the following extensions
- Open your VS Code settings (JSON)
- Add the types directory to
Lua.workspace.library:
{
"Lua.workspace.library": [
// EXISTING LIBRARYS HERE
"C:/path/to/type-gen/types",
],
}--- Adds or updates multiple jobs in shared/jobs.lua.
--- @param newJobs table<string, table> A table where keys are job names
--- @param commitToFile boolean Whether to commit the job data
--- @return boolean success Whether all jobs were successfully created
--- @return string? message An optional message
function CreateJobs(newJobs, commitToFile)
-- Implementation
end
exports('CreateJobs', CreateJobs)exports('CreateJobs', function(newJobs, commitToFile)
-- Implementation
end)GlobalState.weather = "sunny"
GlobalState.policeOnDuty = 5
GlobalState.heistCooldown = true--SERVER
Player(source).state:set("isLoggedIn", true, true)
Player(playerId).state.invBusy = false
--CLIENT
LocalPlayer.state:set("inv_busy", false, true)
LocalPlayer.state.dead = trueThe generator creates type definition files for both exports and state bags:
types/my_resource/server.lua
---@meta
---**`server`**
---Adds or updates multiple jobs in shared/jobs.lua.
---@param newJobs table<string, table> A table where keys are job names
---@param commitToFile boolean Whether to commit the job data
---@return boolean success Whether all jobs were successfully created
---@return string? message An optional message
function exports.my_resource:CreateJobs(newJobs, commitToFile) end- Scanning: Recursively finds all
.luafiles in the input directory (skipping folders matching the excludePatterns config) - Parsing: Extracts
exports()calls, GlobalState assignments, and Player/LocalPlayer state operations - Documentation: Parses LuaDoc comments (
---@param,---@return, etc.) for exports - Type Inference: Infers types from assigned values for state variables
- Context Detection: Determines if exports are client, server, or shared based on file paths
- State Aggregation: Combines state definitions from all resources into unified interfaces
- Generation: Creates properly formatted Lua type definition files
- Use clear LuaDoc comments for best results with exports
- Follow consistent naming conventions
- Place client-side code in files containing "client" in the name
- Place server-side code in files containing "server" in the name
- Shared code goes in files containing "shared" or neither
- See qbx_core/server/functions.lua for an example of "good" LuaDoc documentation
Inspired by ox_types.
MIT