Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[helpers ts conversion] Arrays #16518

Merged
merged 25 commits into from
May 22, 2024
Merged

Conversation

blakewilson
Copy link
Contributor

Q                       A
Fixed Issues? Partial fix for #16500
Patch: Bug Fix? Yes
Major: Breaking Change? No
Minor: New Feature? No
Tests Added + Pass? Yes
Documentation PR Link
Any Dependency Changes?
License MIT

Adds proper types for Array helper methods. Additional comments are provided as inline comments.

@babel-bot
Copy link
Collaborator

babel-bot commented May 20, 2024

Build successful! You can test your changes in the REPL here: https://babeljs.io/repl/build/57008

@blakewilson blakewilson marked this pull request as ready for review May 20, 2024 15:01
@blakewilson
Copy link
Contributor Author

There are some tests failing from the recent suggestions/changes. I'll get those fixed!

@nicolo-ribaudo
Copy link
Member

Oh well, it looks like one of my suggestions was wrong if it changes tests behavior 😅

@blakewilson
Copy link
Contributor Author

blakewilson commented May 20, 2024

Oh well, it looks like one of my suggestions was wrong if it changes tests behavior 😅

@nicolo-ribaudo Yeah I thought it was only an invalid snapshot but it looks like actual tests were failing. I've reverted. Looks like everything is green now.

/* @minVersion 7.0.0-beta.0 */

export default function _iterableToArrayLimitLoose<T>(
arr: Array<T>,
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
arr: Array<T>,
arr: Iterable<T>,

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ahh, right. Now I recall why I did this. It's because we are accessing the .length property below on arr, which only exists on Array. See: #16518 (comment)

var _arr: T[] = [];
var step;
iterator = iterator.call(arr);
while (arr.length < i && !(step = iterator.next()).done) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The function argument arr accepts Array<T> here as we are accessing the .length property, which doesn't exist on normal Iterators.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I suppose this would include String as well. I'll update the arr arg to accept Array<T> | String

Copy link
Member

Choose a reason for hiding this comment

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

Ughhh I'm quite confident that this is a bug, and we should be using _arr instead of arr. Can you mark arr as Iterable<T>, and add a @ts-expect-error here? I'll open an issue to track it.

Copy link
Member

Choose a reason for hiding this comment

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

Oh whaat, this helper (and slicedToArrayLoose) have never been used. They have been introduced in ae7d536, but there has never been any code actually loading them.

It doesn't matter how they are converted to TS at this point -- could you instead open a separate PR to delete them? 😅

Copy link
Member

@nicolo-ribaudo nicolo-ribaudo left a comment

Choose a reason for hiding this comment

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

iterableToArrayLimitLoose.ts needs to be removed in a separate PR. Its types are a bit wrong, but so is them implementation so it's fine.

Copy link
Member

@liuxingbaoyu liuxingbaoyu left a comment

Choose a reason for hiding this comment

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

Thanks!

@nicolo-ribaudo nicolo-ribaudo merged commit 960dacf into babel:main May 22, 2024
51 checks passed
@blakewilson blakewilson deleted the array-types branch May 22, 2024 14:38
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.

None yet

5 participants