From d3b99419a3966e53b7173e0105234e448b1643ed Mon Sep 17 00:00:00 2001 From: Junseo Yoo Date: Mon, 10 Jun 2024 10:47:19 -0700 Subject: [PATCH] Code blocks '''lua -> '''luau --- docs/index-type-operator.md | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/docs/index-type-operator.md b/docs/index-type-operator.md index 0091e9f..6cafd65 100644 --- a/docs/index-type-operator.md +++ b/docs/index-type-operator.md @@ -7,7 +7,7 @@ This RFC proposes the addition of one type operator, `index`, which can be used ## Motivation The primary motivation of this proposal is to allow Luau to define a type by accessing a property of another existing type. For instance, consider the following example code: -```lua +```luau type Person = { age: number, name: string, @@ -34,7 +34,7 @@ The expected outcome of the index type operator is that it will enhance develope ## Design The solution to this problem is a type operator, `index`, that can compute the type based on the static properties of `Person`. Formally, the `index` type operator will take in two arguments: the type to index (indexee) and the type to index it with (indexer). This would allow us to instead write the following code: -```lua +```luau type Person = { age: number, name: string, @@ -53,18 +53,18 @@ type idxType2 = index -- idxType2 = number | string Now, the type of `doSmt()`'s parameter can be defined without declaring a variable `bob`. Additionally, regardless of how the type `Person` grows, `idxType` will always be defined as the union of all the properties. Error messages will be displayed for incorrect type arguments. If the indexer is not a property in the indexee, -```lua +```luau type age = index -- Error message: Property '"ager"' does not exist on type 'Person' ``` If the indexer is not a type, -```lua +```luau local key = "age" type age = index -- Error message: Second argument to index is not a valid index type; Unknown type 'key' ``` Note: these errors will be part of the general type family reduction errors since `index` will be built into the type family system. The indexee may be a union type. In this case, the type operator will distribute the arguments to multiple type families: -```lua +```luau type Person2 = { age: string } @@ -77,7 +77,7 @@ type idxType4 = index -- Error message: Prope ``` In the circumstance that the indexee is a type class or table with an `__index` metamethod, the `__index` metamethod will *only* be invoked if the indexer is not found within the current scope: -```lua +```luau local exampleClass = { Foo = "eight" } local exampleClass2 = setmetatable({ Foo = 8 }, { __index = exampleClass }) local exampleClass3 = setmetatable({ Bar = "nine" }, { __index = exampleClass }) @@ -98,7 +98,7 @@ A drawback to this feature is the possible increase in the cost of maintenance. ## Alternatives An alternative design can be depicted from the example below: -```lua +```luau type Person3 = { age: number, name: string,