Fixed out of spec behavior of array.reduce (#731) · lineCode/TypeScriptToLua@b26ec48 · GitHub
Skip to content

Commit b26ec48

Browse files
authored
Fixed out of spec behavior of array.reduce (TypeScriptToLua#731)
* Fixed out of spec behavior of array.reduce * Moved select declarations from ArrayReduce to lualib declaration files * Fixed issue in reduce with undefined returning callback * Changed reduce loop from while to for for performance reasons * Cleaned up code a little from PR feedback * testcase formatting
1 parent c1e77c9 commit b26ec48

4 files changed

Lines changed: 38 additions & 12 deletions

File tree

‎src/lualib/ArrayReduce.ts‎

Lines changed: 13 additions & 12 deletions

‎src/lualib/declarations/global.d.ts‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,6 @@ declare function rawset<T, K extends keyof T>(table: T, key: K, val: T[K]): void
1616
declare function next<K, V>(table: Record<any, V>, index?: K): [K, V];
1717
declare function pcall(func: () => any): any;
1818
declare function unpack<T>(list: T[], i?: number, j?: number): T[];
19+
20+
declare function select<T>(index: number, ...args: T[]): T;
21+
declare function select<T>(index: "#", ...args: T[]): number;

‎src/lualib/declarations/tstl.d.ts‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
/** @noSelfInFile */
22

3+
/** @vararg */
4+
interface Vararg<T> extends Array<T> {}
5+
6+
/** @forRange */
7+
declare function forRange(start: number, limit: number, step?: number): number[];
8+
39
interface LuaClass {
410
prototype: LuaObject;
511
____super?: LuaClass;

‎test/unit/builtins/array.spec.ts‎

Lines changed: 16 additions & 0 deletions

0 commit comments

Comments
 (0)