1
0
Fork 0
mirror of https://github.com/luau-lang/rfcs.git synced 2025-04-12 14:30:56 +01:00

Update generic-constraints.md

oops, fixed where clause for function type
This commit is contained in:
Kiiyoko 2024-12-13 19:09:12 -05:00 committed by GitHub
parent 8e20e26f6c
commit 690f8b7676
Signed by: DevComp
GPG key ID: B5690EEEBB952194

View file

@ -47,7 +47,7 @@ local function getProperty<T, K where K: keyof<T>>( object: T, key: K ): index<T
return object[ key ]
end
type getProperty<T, K> = ( object: T, key: K ) -> ( index<T, K> ) where< K: keyof<T> >
type getProperty<T, K where K: keyof<T>> = ( object: T, key: K ) -> ( index<T, K> )
```
This would allow users to specify the constraints of the separately from the generic declaration itself. This would be reminiscent to users of C#. Imposing multiple constraints on different generics can be done by delimiting with `,`. This would be backwards compatible, without major performance implications, as it could just be a conditional keyword. This could be used in conjuction with option 1.
> This isn't nearly as elegant for smaller types compared to option 1, but would be incredibly powerful for generics with lots of constraints. This allows for neatly distributing the declaration along multiple lines.