Overview
@cast tells GLuaLS to treat a variable as a specific type from that line onward. Use it to narrow unions, assert non-nil values, or correct inference in dynamic code.
Syntax
Basic type assertion
Non-nil assertion
Casting to a more specific type
Adding to a union
Removing from a union
Inline table casting
When to use @cast vs @type
- Use
@typeon new variable declarations when GLuaLS cannot infer the type - Use
@castafter a variable already exists to narrow or correct its type without redeclaring it