Created
April 9, 2019 03:49
-
-
Save hazzard993/71ad5d1e43a2fdeecf33fc976ceddd1c to your computer and use it in GitHub Desktop.
In TSTL, iterate using pairs, not Symbol.Iterator
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Works on 0.17.0 | |
/** | |
* @tupleReturn | |
* @luaIterator | |
*/ | |
declare function pairs(object: object): Iterable<[string, any]>; | |
declare const print: any; | |
let o = { a: 0, b: 1, c: 2 }; | |
for (const [key, value] of pairs(o)) { | |
print(key, value); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
https://typescripttolua.github.io/play.html#src=%2F%2F%20Works%20on%200.17.0%0A%0A%2F**%0A%20*%20%40tupleReturn%0A%20*%20%40luaIterator%0A%20*%2F%0Adeclare%20function%20pairs(object%3A%20object)%3A%20Iterable%3C%5Bstring%2C%20any%5D%3E%3B%0A%0Adeclare%20const%20print%3A%20any%3B%0A%0Alet%20o%20%3D%20%7B%20a%3A%200%2C%20b%3A%201%2C%20c%3A%202%20%7D%3B%0A%0Afor%20(const%20%5Bkey%2C%20value%5D%20of%20pairs(o))%20%7B%0A%20%20%20%20print(key%2C%20value)%3B%0A%7D