From 353e69324b7006e5d487814aaa91f11621256dbd Mon Sep 17 00:00:00 2001 From: T 'Filtered' C Date: Fri, 13 Jan 2023 01:59:26 +0000 Subject: [PATCH] Update constrained-generics.md --- rfcs/constrained-generics.md | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/rfcs/constrained-generics.md b/rfcs/constrained-generics.md index db7493e0..e47d542f 100644 --- a/rfcs/constrained-generics.md +++ b/rfcs/constrained-generics.md @@ -31,6 +31,8 @@ SomethingWithAGenericTable({meow = 5}) --OK SomethingWithAGenericTable(5) --not OK ``` +> TODO: Partially constrained generics, where part of the type is known but can be expaned upon, similar to TypeScript's `extends` keyword. + ## Drawbacks This adds unusual syntax, as well as adding to the complexity of the language. @@ -39,4 +41,9 @@ This also doesn't address how this should be approached around type packs. ## Alternatives -Do nothing, and use the `assert(type(T) == T)` syntax, though this creates extra bytecode. +Use something similar to Rust's `where` syntax: +```lua +local function SomethingWithAGenericTable(tab: T) where T: {[string]: any} +``` + +Do nothing, and use the `assert(type(T) == T)` syntax, though this creates extra bytecode. It also casts the object as `never`, which removes the type errors, however no autocomplete information is generated.