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

Add Array.prototype.findLast() and Array.prototype.findLastIndex() #49636

Merged
merged 4 commits into from
Jan 13, 2023

Conversation

m-basov
Copy link
Contributor

@m-basov m-basov commented Jun 22, 2022

Describe your changes
Add type definitions for Array.prototype.findLast() and Array.prototype.findLastIndex() methods. Both methods were added to the es2023 lib but the lib didn't exist so I've created it. The definitions are identical to .find() and .findIndex() but with updated comments.

Testing performed
Added findLast.ts test file where all Array interfaces try to call .findLast() and .findLastIndex().
Also, tested it manually by running:

  • tsc with the es5 target and libs: []
  • tsc with the es5 target and libs: ["es2023"]
  • tsc with the es5 target and libs: ["esnext"]

Additional context
The es2023 target were added using this PR #46291 as an example.

Fixes #48829

Credits to Bloomberg colleagues who helped with reviews @acutmore @dragomirtitian @mkubilayk.

@typescript-bot
Copy link
Collaborator

Thanks for the PR! It looks like you've changed the TSServer protocol in some way. Please ensure that any changes here don't break consumers of the current TSServer API. For some extra review, we'll ping @sheetalkamat, @amcasey, @mjbvz, @minestarks for you. Feel free to loop in other consumers/maintainers if necessary

@typescript-bot typescript-bot added the For Milestone Bug PRs that fix a bug with a specific milestone label Jun 22, 2022
@ghost
Copy link

ghost commented Jun 22, 2022

CLA assistant check
Thank you for your submission, we really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.

❌ m-basov sign now
You have signed the CLA already but the status is still pending? Let us recheck it.

@mkubilayk
Copy link
Contributor

mkubilayk commented Jun 22, 2022

@DanielRosenwasser Has there been any changes to the CLA bot? I believe it used to accept contributions from the Bloomberg fork automatically.

Edit: Fixed now - thanks!

Copy link
Member

@sandersn sandersn left a comment

Choose a reason for hiding this comment

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

Looks good except that TransformFlags ran out of space. @rbuckton, do you have any ideas for how to move any other members out of it?

ContainsES2016 = 1 << 10,
ContainsES2015 = 1 << 11,
ContainsGenerator = 1 << 12,
ContainsDestructuringAssignment = 1 << 13,
Copy link
Member

Choose a reason for hiding this comment

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

this now overlaps with ContainsTypeScriptClassSyntax = 1 << 13, which means we're officially out of space in TransformFlags. =(

Paging @rbuckton for advice.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for the review! I've assumed the overlap was intentional from the ES2022 PR but apparently it was fixed later by shifting Markers. There is no more space for that now though.

src/compiler/types.ts Outdated Show resolved Hide resolved
src/compiler/types.ts Outdated Show resolved Hide resolved
@@ -0,0 +1,27 @@
// @target: es2023, esnext

[0].findLast((item) => item === 0);
Copy link
Member

Choose a reason for hiding this comment

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

Can you add a test for the generic overload of findLast?

@@ -6523,6 +6523,7 @@ namespace ts {
ES2020 = 7,
ES2021 = 8,
ES2022 = 9,
ES2023 = 10,
Copy link
Member

Choose a reason for hiding this comment

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

@DanielRosenwasser: Do we normally add a new script target before that edition is ratified, or do we put everything in esnext until there's an official spec?

Copy link
Member

@DanielRosenwasser DanielRosenwasser Jan 13, 2023

Choose a reason for hiding this comment

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

I think it's okay to put it into 2023 since we're expecting ratification before the stable release of TS5.0.

@DanielRosenwasser
Copy link
Member

DanielRosenwasser commented Aug 2, 2022

I believe we wait for ratification because the target isn't stable. lib might be different though?

@sandersn
Copy link
Member

sandersn commented Aug 2, 2022

I'd vote to wait to add es2023 until that edition is ratified. It could go into esnext for now.

@m-basov
Copy link
Contributor Author

m-basov commented Aug 25, 2022

I removed ES2023 target and left ES2023 lib as @DanielRosenwasser suggested. Could you take one more look @sandersn @rbuckton please? Thanks!

Copy link
Member

@sandersn sandersn left a comment

Choose a reason for hiding this comment

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

Looks good. Can you merge from main so before I merge it?

@m-basov
Copy link
Contributor Author

m-basov commented Aug 31, 2022

@sandersn done! Rebased on main.

src/lib/es2023.array.d.ts Outdated Show resolved Hide resolved
src/lib/es2023.array.d.ts Outdated Show resolved Hide resolved
src/lib/es2023.array.d.ts Outdated Show resolved Hide resolved
src/lib/es2023.array.d.ts Outdated Show resolved Hide resolved
@graphemecluster
Copy link
Contributor

(I am not a member of TypeScript; I just reviewed based on my experience. Do point out me if I made something wrong.)

@robpalme
Copy link

robpalme commented Oct 7, 2022

Current status: @m-basov is waiting on #50450 by @graphemecluster to be merged. Once that lands he will rebase this PR.

@graphemecluster
Copy link
Contributor

@robpalme Thanks, I've just resolved the conflicts of my PRs.
And sorry if I interpret this incorrectly, but if Bloomberg would like to see my PRs being merged, please do anything that speeds up the review process, or otherwise anything that could get it started quicker, as it has been a while since I work on them. Appreciate your support on it!

@DanielRosenwasser
Copy link
Member

Can we just implement this based on the existing signatures of find and findIndex, and then handle the changes to findLast* in #50450? That one is a much harder change to evaluate w.r.t. ecosystem impact, and there's no reason to block this on it.

@graphemecluster
Copy link
Contributor

@DanielRosenwasser I suppose the only difference is whether or not the this in the predicate should be typed void (and whether to repeat the documentation). The others are, most likely, errors not existing in the current find* signature.

@m-basov
Copy link
Contributor Author

m-basov commented Nov 11, 2022

Sure, I will rebase my changes on the latest main branch.

UPD. The branch is rebased now but CLA isn't working for some reason.

@DanielRosenwasser
Copy link
Member

Looks like we have some merge conflicts. Would you be able to fix those up?

Also, @rbuckton would you be able to take a second look?

@DanielRosenwasser
Copy link
Member

@typescript-bot pack this
@typescript-bot test top100
@typescript-bot run dt

@typescript-bot
Copy link
Collaborator

typescript-bot commented Jan 13, 2023

Heya @DanielRosenwasser, I've started to run the tarball bundle task on this PR at 95fab91. You can monitor the build here.

@typescript-bot
Copy link
Collaborator

typescript-bot commented Jan 13, 2023

Heya @DanielRosenwasser, I've started to run the diff-based top-repos suite on this PR at 95fab91. You can monitor the build here.

Update: The results are in!

@typescript-bot
Copy link
Collaborator

typescript-bot commented Jan 13, 2023

Heya @DanielRosenwasser, I've started to run the parallelized Definitely Typed test suite on this PR at 95fab91. You can monitor the build here.

@typescript-bot
Copy link
Collaborator

typescript-bot commented Jan 13, 2023

Hey @DanielRosenwasser, I've packed this into an installable tgz. You can install it for testing by referencing it in your package.json like so:

{
    "devDependencies": {
        "typescript": "https://typescript.visualstudio.com/cf7ac146-d525-443c-b23c-0d58337efebc/_apis/build/builds/142507/artifacts?artifactName=tgz&fileId=7EC6C5954393EDF3948E05E7C7D7AA40EB6F5EEDEA27C4226952B5F1C991319F02&fileName=/typescript-5.0.0-insiders.20230113.tgz"
    }
}

and then running npm install.


There is also a playground for this build and an npm module you can use via "typescript": "npm:@typescript-deploys/pr-build@5.0.0-pr-49636-19".;

@typescript-bot
Copy link
Collaborator

@DanielRosenwasser Here are the results of running the top-repos suite comparing main and refs/pull/49636/merge:

Everything looks good!

m-basov and others added 4 commits January 13, 2023 09:10
* Add .findLast(), .findLastIndex(), and es2023 target

Signed-off-by: mbasov2 <mbasov2@bloomberg.net>

* Update baselines

Signed-off-by: mbasov2 <mbasov2@bloomberg.net>

Remove ES2023 target (#75)

Signed-off-by: mbasov2 <mbasov2@bloomberg.net>
Signed-off-by: mbasov2 <mbasov2@bloomberg.net>
@m-basov
Copy link
Contributor Author

m-basov commented Jan 13, 2023

@DanielRosenwasser thanks for review. I've fixed the merge conflicts.

@graphemecluster thanks for spotting the issue with Uint8ClampedArray[]. It's fixed now but I cannot find your comment in the GH UI (I noticed it on email).

@m-basov
Copy link
Contributor Author

m-basov commented Jan 13, 2023

@microsoft-github-policy-service agree company="Bloomberg"

Copy link
Member

@rbuckton rbuckton left a comment

Choose a reason for hiding this comment

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

I'm a bit wary about adding an es2023 lib given that the committee has not yet ratified ES2023, but given that Array find from last is at Stage 4, this is probably fine.

@sandersn sandersn merged commit cb4c768 into microsoft:main Jan 13, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
For Milestone Bug PRs that fix a bug with a specific milestone
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

Add Array.prototype.findLast and Array.prototype.findLastIndex
8 participants