> ## Documentation Index
> Fetch the complete documentation index at: https://gluals.arnux.net/llms.txt
> Use this file to discover all available pages before exploring further.

# @alias

> Create named type aliases for use across your codebase.

## Overview

`@alias` gives a type expression a name. Use it for long types or types you reuse across your addon.

***

## Syntax

```lua theme={null}
---@alias AliasName TypeExpression

---@alias AliasName
---| "value1" # description
---| "value2" # description
```

***

## Simple aliases

```lua theme={null}
---@alias ID number
---@alias PlayerName string
---@alias Callback fun(result: any): nil
```

After you define an alias, use its name anywhere GLuaLS expects a type:

```lua theme={null}
---@param id ID
---@return PlayerName
function GetPlayerName(id) end
```

***

## Union aliases

```lua theme={null}
---@alias StringOrNumber string | number
---@alias MaybePlayer Player | nil
```

***

## String literal enumerations

Use `---|` to list allowed string values:

```lua theme={null}
---@alias Realm
---| "client" # Runs on clients only
---| "server" # Runs on the server only
---| "shared" # Runs on both server and clients

---@param realm Realm
function SetDefaultRealm(realm) end
```

When you use this alias as a parameter type, completions show the listed string values.

***

## Generic aliases

```lua theme={null}
---@alias Callback<T> fun(result: T, err: string?): nil
---@alias Pair<K, V> { key: K, value: V }
```

***

## Common GMod patterns

```lua theme={null}
---@alias HookName string  -- or a union of known hook name literals

---@alias NetMessageName string

---@alias ConVarCallback fun(cv: ConVar, oldVal: string, newVal: string): nil
```
