Skip to content

Variadic type parameters #1112

@Frityet

Description

@Frityet

Right now, using functions with generics is quite awkward in teal, where you cant have any number of function params or returns, you must either take in the entire function as a type or deal with only 1 param/return:

local function my_cool_func<TRet, TArg>(x: function(TArg): TRet, y: TArg): TRet
    --some cool invocation magic
end

where it would fail if you tried to call it with something like:

local function add(x: integer, y: integer): integer
    return x + y
end

local val = my_cool_func(add, 1, 2)

In order to make this work, you could do something like:

local function my_cool_func<TFn>(x: TFn, ...args: any): any
   --some cool invocation magic
end

but now almost all type info is lost.

It would be cool if it would be possible to do "varadict generics", allowing for patterns such as:

local function my_cool_function<TRet, ...TArg>(x: function(TArg...): TRet, ...args: TArg...): TRet
   --even safer invocation magic
end

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions