This annotation is intended for complex cases and is primarily designed to be used by the built-in annotations.
Overview
valid_guard marks a function such as IsValid that returns true only when its first argument is a valid object. After the check, GLuaLS treats the value as valid, so need-check-nil and unchecked-nil-access stop warning about it.
The official annotations already mark IsValid and similar Garry’s Mod helpers.
Syntax
@return line. The function must return TypeGuard<T>.
Example
PhysObj or Panel, keeps that type after the check.
Keep it narrow
Only usevalid_guard on a function that really checks validity. Marking a function that does not hides real nil and NULL bugs.
It applies only to calls of the annotated function. A local function with the same name is a separate function.
See also
@self_guard: a method that proves its receiver is valid@self_call_valid: a callback where aselfmethod always returns a valid value