mirror of
https://github.com/luau-lang/rfcs.git
synced 2025-05-04 10:43:48 +01:00
Describe rules surrounding duplicate record fields.
This commit is contained in:
parent
435a9d103d
commit
f5447a8706
1 changed files with 16 additions and 0 deletions
|
@ -54,6 +54,22 @@ type MixedMap = { read [string]: Animal, write [string]: Dog }
|
|||
type MixedArray = { read Animal, write Dog }
|
||||
```
|
||||
|
||||
Redundant record fields are still disallowed: Each field may have at most one
|
||||
read type and one write type:
|
||||
|
||||
```lua
|
||||
type A = { read x: string, write x: "Hello" } -- OK
|
||||
type C = { read x: string, read x: "hello" } -- ERROR
|
||||
type B = { x: string, read x: "hello" } -- ERROR
|
||||
```
|
||||
|
||||
We place no restriction on the relationship between the read and write type.
|
||||
The following is certainly a bad idea, but it is legal:
|
||||
|
||||
```lua
|
||||
type T = { read n: number, write n: string }
|
||||
```
|
||||
|
||||
This syntax is readable, matches the flavour of preexisting Luau syntax well,
|
||||
and is pretty easy to parse efficiently.
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue