mirror of
https://github.com/luau-lang/luau.git
synced 2025-04-10 22:00:54 +01:00
Document variadic types (#17)
This commit is contained in:
parent
5f49e3fd95
commit
a124f53628
1 changed files with 20 additions and 0 deletions
|
@ -234,6 +234,26 @@ Note: it's impossible to create an intersection type of some primitive types, e.
|
||||||
|
|
||||||
Note: Luau still does not support user-defined overloaded functions. Some of Roblox and Lua 5.1 functions have different function signature, so inherently requires overloaded functions.
|
Note: Luau still does not support user-defined overloaded functions. Some of Roblox and Lua 5.1 functions have different function signature, so inherently requires overloaded functions.
|
||||||
|
|
||||||
|
## Variadic types
|
||||||
|
|
||||||
|
Luau permits assigning a type to the `...` variadic symbol like any other parameter:
|
||||||
|
|
||||||
|
```lua
|
||||||
|
local function f(...: number)
|
||||||
|
end
|
||||||
|
|
||||||
|
f(1, 2, 3) -- ok
|
||||||
|
f(1, "string") -- not ok
|
||||||
|
```
|
||||||
|
|
||||||
|
`f` accepts any number of `number` values.
|
||||||
|
|
||||||
|
In type annotations, this is written as `...T`:
|
||||||
|
|
||||||
|
```lua
|
||||||
|
type F = (...number) -> ...string
|
||||||
|
```
|
||||||
|
|
||||||
## Typing idiomatic OOP
|
## Typing idiomatic OOP
|
||||||
|
|
||||||
One common pattern we see throughout Roblox is this OOP idiom. A downside with this pattern is that it does not automatically create a type binding for an instance of that class, so one has to write `type Account = typeof(Account.new("", 0))`.
|
One common pattern we see throughout Roblox is this OOP idiom. A downside with this pattern is that it does not automatically create a type binding for an instance of that class, so one has to write `type Account = typeof(Account.new("", 0))`.
|
||||||
|
|
Loading…
Add table
Reference in a new issue