Skip to content

Conversation

@Perryvw
Copy link
Member

@Perryvw Perryvw commented Jun 12, 2021

Closes #1028

@Perryvw Perryvw requested review from lolleko and tomblind June 12, 2021 12:06
return result;
},
};
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not just this?

function __TS__ArrayEntries<T>(this: void, array: T[]) {
    return ipairs(array);
}

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because TS defines the type of entries as returning IterableIterator<[number, T]>, and I don't think ipairs LuaIterable<LuaMultiReturn<[number, NonNullable<T>]>> is 1:1 assignable to that since it's a different iterator kind and also the lack of LuaMultiReturn.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah yeah, that would be a problem if used indirectly. It's a shame since this version is so much more complex.

It might be good to add a test for indirect use:

...
const entries = array.entries();
for (const [i, v] of entries) {
...

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good call, added a test for indirect use as well as destructuring, those both fail if ipairs is used

@Perryvw Perryvw merged commit ffde390 into master Jun 12, 2021
@Perryvw Perryvw deleted the feature/array-entries branch June 12, 2021 12:55
sanikoyes pushed a commit to sanikoyes/TypeScriptToLua that referenced this pull request Sep 24, 2021
* Implement array.entries

* Added extra test for indirect use of array.entries()

* Added destructuring test for array.entries

* Fix prettier
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Implement array.entries

2 participants