From 60032131e238885279169033d6bdcab3746106c5 Mon Sep 17 00:00:00 2001 From: Kiiyoko <73446312+Kiiyoko@users.noreply.github.com> Date: Thu, 12 Dec 2024 23:16:27 -0500 Subject: [PATCH] Update generic-constraints.md fixed syntax --- docs/generic-constraints.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/generic-constraints.md b/docs/generic-constraints.md index daad262..0fb0262 100644 --- a/docs/generic-constraints.md +++ b/docs/generic-constraints.md @@ -40,7 +40,7 @@ The following snippet would also thus be correctly inferred. ```lua local qux = { foo = 10, bar = "string" } -local function callbackProperty<T, K & keyof(T)>( object: T, key: K, callback: (index<T, K>) -> () ) +local function callbackProperty<T, K & keyof<T>>( object: T, key: K, callback: (index<T, K>) -> () ) callback( object[key] ) end @@ -51,7 +51,7 @@ end) An alternative syntax could be the following, but does not satisfy current requirements about `:` only being used inside `()` and `{}`, and personally does not look as good. ```lua local function getProperty<T, K: keyof<T>>( object: T, key: K ) ... end -local function callbackProperty<T, K: keyof(T)>( object: T, key: K, callback: (index<T, K>) -> () ) ... end +local function callbackProperty<T, K: keyof<T>>( object: T, key: K, callback: (index<T, K>) -> () ) ... end ``` ## Drawbacks - I am not personally familiar with the internals of the typechecker, but this has a chance to further complicate type inference.