← Luau typing quick reference

Dictionaries and maps

Luau 0.731 · --!strict
{[Key]: Value}

A keyed table that may be sparse. A numeric key does not make a table an array when its indexes are arbitrary.

When to use it

Read this page when you need to apply Dictionaries and maps, verify its exact contract, and adapt the example without bypassing validation or host boundaries.

  • {[string]: number} means string key to number value.
  • Do not use #table or ipairs for a sparse dictionary.

Focused example

--!strict

local pending: {[number]: string} = {}

pending[42] = "save"
pending[105] = "restore"

local operation: string? = pending[42]
pending[42] = nil

local remaining = 0
for requestId, name in pairs(pending) do
    assert(requestId > 0 and #name > 0)
    remaining += 1
end

assert(operation == "save" and remaining == 1)

Complete inventory

View all pages in Luau typing quick reference
← Previous: ArraysNext: Record types →