FiveM TypeScript Usage Guide
This guide covers TypeScript development for FiveM with key differences from Lua.
⚠️ Critical Import Requirement
IMPORTANT: All scripts MUST be imported in their respective main.ts files to be built.
Client-side (src/client/main.ts):
/// <reference types="@citizenfx/client" />
import './my-script';Server-side (src/server/main.ts):
/// <reference types="@citizenfx/server" />
import './my-script';Basic Types
Variables
Lua:
local playerName = "John"
local playerHealth = 100
local isAlive = trueTypeScript:
/// <reference types="@citizenfx/client" />
let playerName: string = "John";
const playerHealth: number = 100;
const isAlive: boolean = true;Arrays
Lua:
TypeScript:
Functions
Lua:
TypeScript:
Events
Lua:
TypeScript:
Tables vs Objects
Lua:
TypeScript:
FiveM-Specific Types
Vector Types
Entity Types
Key Differences
Type References
TypeScript requires type references at the top of every file:
Import/Export System
Lua (no imports needed):
TypeScript (must import):
Event System: on vs onNet
on - For client/server specific events:
onNet - For cross-side events (can be triggered from either side):
Commands
Lua:
TypeScript:
Error Handling
Lua:
TypeScript:
Best Practices
Always add type references at the top of files
Import all new files in main.ts
Use TypeScript interfaces for data structures
Handle errors with try-catch blocks
Use const for values that don't change
Use let for values that do change
Avoid var (it's function-scoped, not block-scoped)
Last updated