From 9d4f3384736fd20f1d3c04e921bb23a34cd15bbb Mon Sep 17 00:00:00 2001 From: Arseny Kapoulkine Date: Tue, 20 Oct 2020 17:47:48 -0700 Subject: [PATCH] Update syntax.md Add short-hand array like table syntax. --- docs/syntax.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/docs/syntax.md b/docs/syntax.md index baea0a5c..c4cac9a1 100644 --- a/docs/syntax.md +++ b/docs/syntax.md @@ -128,6 +128,8 @@ local array: { [number] : string } local object: { x: number, y: string } ``` +When the table consists of values keyed by numbers, it's called an array-like table and has a special short-hand syntax, `{T}` (e.g. `{string}`). + Additionally, the type syntax supports type intersections (`((number) -> string) & ((boolean) -> string)`) and unions (`(number | boolean) -> string`). An intersection represents a type with values that conform to both sides at the same time, which is useful for overloaded functions; a union represents a type that can store values of either type - `any` is technically a union of all possible types. It's common in Lua for function arguments or other values to store either a value of a given type or `nil`; this is represented as a union (`number | nil`), but can be specified using `?` as a shorthand syntax (`number?`).