mirror of
https://github.com/luau-lang/luau.git
synced 2025-05-04 10:33:46 +01:00
Update constrained-generics.md
This commit is contained in:
parent
16970abbfb
commit
353e69324b
1 changed files with 8 additions and 1 deletions
|
@ -31,6 +31,8 @@ SomethingWithAGenericTable({meow = 5}) --OK
|
||||||
SomethingWithAGenericTable(5) --not 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
|
## Drawbacks
|
||||||
|
|
||||||
This adds unusual syntax, as well as adding to the complexity of the language.
|
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
|
## 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<T>(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.
|
||||||
|
|
Loading…
Add table
Reference in a new issue