@@ -478,3 +478,43 @@ describe("vararg spread in IIFE", () => {
478478 ` . expectToMatchJsResult ( ) ;
479479 } ) ;
480480} ) ;
481+
482+ // https://github.com/TypeScriptToLua/TypeScriptToLua/issues/1244
483+ test . each ( [ "pairs" , "ipairs" ] ) ( "can spread %s (#1244)" , func => {
484+ util . testFunction `
485+ const arr = ["a", "b", "c"];
486+ return [...${ func } (arr)];
487+ `
488+ . withLanguageExtensions ( )
489+ . setTsHeader (
490+ `
491+ declare function ipairs<T>(this: void, t: T): LuaIterable<LuaMultiReturn<[number, NonNullable<T[keyof T]>]>>;
492+ declare function pairs<T>(this: void, t: T): LuaIterable<LuaMultiReturn<[keyof T, NonNullable<T[keyof T]>]>>;
493+ `
494+ )
495+ . expectToEqual ( [
496+ [ 1 , "a" ] ,
497+ [ 2 , "b" ] ,
498+ [ 3 , "c" ] ,
499+ ] ) ;
500+ } ) ;
501+
502+ // https://github.com/TypeScriptToLua/TypeScriptToLua/issues/1244
503+ test . each ( [ "LuaTable" , "LuaMap" ] ) ( "can spread %s (#1244)" , type => {
504+ const result : Array < [ string , string ] > = util . testFunction `
505+ const tbl = new ${ type } ();
506+ tbl.set("foo", "bar");
507+ tbl.set("fizz", "buzz");
508+ return [...pairs(tbl)];
509+ `
510+ . withLanguageExtensions ( )
511+ . setTsHeader (
512+ "declare function pairs<T>(this: void, t: T): LuaIterable<LuaMultiReturn<[keyof T, NonNullable<T[keyof T]>]>>;"
513+ )
514+ . getLuaExecutionResult ( ) ;
515+
516+ // We don't know the order so match like this
517+ expect ( result ) . toHaveLength ( 2 ) ;
518+ expect ( result . some ( ( [ k , v ] ) => k === "foo" && v === "bar" ) ) . toBe ( true ) ;
519+ expect ( result . some ( ( [ k , v ] ) => k === "fizz" && v === "buzz" ) ) . toBe ( true ) ;
520+ } ) ;
0 commit comments