Skip to content

Commit 96bb9a6

Browse files
committed
feat(table): add generics to some functions
1 parent f934754 commit 96bb9a6

2 files changed

Lines changed: 7 additions & 7 deletions

File tree

core/table.d.ts

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,17 +17,12 @@ declare namespace table {
1717
function insert<T>(list: T[], value: T): void;
1818
function insert<T>(list: T[], pos: number, value: T): void;
1919

20-
/**
21-
* Returns a new table with all parameters stored into keys 1, 2, etc. and with a field "n" with the total number of parameters. Note that the resulting table may not be a sequence.
22-
*/
23-
function pack(...args: any[]): any[];
24-
2520
/**
2621
* Removes from list the element at position pos, returning the value of the removed element. When pos is an integer between 1 and #list, it shifts down the elements list[pos+1], list[pos+2], ···, list[#list] and erases element list[#list]; The index pos can also be 0 when #list is 0, or #list + 1; in those cases, the function erases the element list[pos].
2722
*
2823
* The default value for pos is #list, so that a call table.remove(l) removes the last element of list l.
2924
*/
30-
function remove(list: any[], pos?: number): any[];
25+
function remove<T>(list: T[], pos?: number): T | undefined;
3126

3227
/**
3328
* Sorts list elements in a given order, in-place, from list[1] to list[#list]. If comp is given, then it must be a function that receives two list elements and returns true when the first element must come before the second in the final order (so that, after the sort, i < j implies not comp(list[j],list[i])). If comp is not given, then the standard Lua operator < is used instead.
@@ -36,5 +31,5 @@ declare namespace table {
3631
*
3732
* The sort algorithm is not stable: elements considered equal by the given order may have their relative positions changed by the sort.
3833
*/
39-
function sort(list: any[], comp?: (a: any, b: any) => boolean): any[];
34+
function sort<T>(list: T[], comp?: (a: T, b: T) => boolean): T[];
4035
}

special/5.2-plus.d.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,11 @@ declare namespace table {
5656
*/
5757
function unpack<T extends any[]>(list: T): T;
5858
function unpack<T>(list: T[], i: number, j?: number): T[];
59+
60+
/**
61+
* Returns a new table with all parameters stored into keys 1, 2, etc. and with a field "n" with the total number of parameters. Note that the resulting table may not be a sequence.
62+
*/
63+
function pack<T extends any[]>(...args: T): T & { n: number };
5964
}
6065

6166
declare namespace os {

0 commit comments

Comments
 (0)