Skip to content

Add Array.prototype.findLast and Array.prototype.findLastIndex #48829

Closed

Description

@yume-chan

lib Update Request

Configuration Check

My compilation target is ES5 and my lib is ESNext.

Missing / Incorrect Definition

Missing Array.prototype.findLast and Array.prototype.findLastIndex

Sample Code

[3, 2, 1].findLast(x => x > 2);

Documentation Link

Proposal: https://tc39.es/proposal-array-find-from-last/ (currently stage 3 4)
Can I Use: https://caniuse.com/mdn-javascript_builtins_array_findlast (Chrome and Safari already shipped it without flags)

Activity

  1. andrewbranch commented on Apr 25, 2022

    @andrewbranch
    Member

    [Double checking with Daniel Rosenwasser (@DanielRosenwasser) that stage 3 is the only criteria for adding to lib.esnext]

  2. DanielRosenwasser commented on Apr 26, 2022

    @DanielRosenwasser
    Member

    It is, but if I ask for stage 4 at an upcoming meeting we might as well add it to a stable version.

  3. fatcerberus commented on Apr 27, 2022

    @fatcerberus

    Seems weird that Firefox hasn’t implemented it yet, that’s a bit unfortunate.

  4. Kingwl commented on Apr 28, 2022

    @Kingwl
    Contributor

    Seems weird that Firefox hasn’t implemented it yet, that’s a bit unfortunate.

    Sorry....My fault.

  5. fatcerberus commented on Apr 28, 2022

    @fatcerberus

    Wenlu Wang (@Kingwl) It’s your fault that Firefox doesn’t support this API? What?

  6. DanielRosenwasser commented on Jun 6, 2022

    @DanielRosenwasser
    Member

    Bruce Pascoe (@fatcerberus), the context is that Wenlu Wang (@Kingwl) is contributing the changeset to Firefox.

    By the way, we reached Stage 4 today! 🎉🎉🎉

    I believe that means we should add this to lib.es2023.array.d.ts.

  7. changed the title [-][lib] missing `Array.prototype.findLast` and `Array.prototype.findLastIndex`[/-] [+]Add `Array.prototype.findLast` and `Array.prototype.findLastIndex`[/+] on Jun 6, 2022
  8. monikams commented on Oct 12, 2022

    @monikams

    With which version of typescript I could use the method findLast?

  9. 16 remaining items

  10. cristan commented on Apr 13, 2023

    @cristan

    It works on TypeScript 5 at least at the playground typescriptlang.org: example. It doesn't say much though: it also works just fine if you select Typescript 4.

    Also note that you'll need at least Node.JS 18, as that's the lowest version that supports findLast (source).

  11. BR0kEN- commented on Apr 18, 2023

    @BR0kEN-

    It works only in TS 5 and only when the target is ESNext.

  12. juneate commented on Apr 25, 2023

    @juneate

    Cristan Meijer (@cristan) It works on TypeScript 5 at least at the playground typescriptlang.org

    Incorrect, as you can see here:
    image

    As Sergii Bondarenko (@BR0kEN-) said, if you change the target in that environment, the issue disappears. But if you try to "Export" the example to CodeSandbox with the same settings, it triggers the issue again.

    image

    Tried also updating to the latest Typyscript 5.1 build, no change.

  13. cristan commented on Jun 26, 2023

    @cristan

    findLast was introduced in EcmaScript 2023. However, es2023 isn't supported in Typescript 5. Maybe that's it?

    es2023 not supported
  14. shakedhagag commented on Sep 13, 2023

    @shakedhagag

    Is there any progress with this issue?

  15. jacobbogers commented on Oct 26, 2023

    @jacobbogers

    Is there any progress on this issue?

  16. RyanCavanaugh commented on Oct 26, 2023

    @RyanCavanaugh
    Member

    There's not progress because it was fixed in 2022. If you're not seeing findLast / etc, you have a configuration issue. Seek support at StackOverflow, Discord, etc.

  17. cristan commented on Dec 19, 2023

    @cristan

    Ah, it indeed does work, but the problem is indeed that findLast was introduced in EcmaScript 2023. You'll need Node.JS 18 or higher for that, but that that isn't much of a problem. TypeScript is slightly more problematic:

    Setting the target to es2023 even in TypeScript 5.3.3 yields the same error I had before. However, findLast does work when setting the target to esnext ^_^

    In the handbook, you'll see that es2023 is indeed not an option. It also states: "esnext is a moving target that may include support for Stage 3 proposals to ECMAScript modules". So I would much rather set the target explicitly to es2023 instead to this vague concept, but hey, it works.

  18. GoRRRRchik commented on Feb 20, 2024

    @GoRRRRchik

    here is the solution

    make the declaration under your code with findLastIndex

    Array.prototype.findLastIndex = function(predicate) { for (let i = this.length - 1; i >= 0; i--) { if (predicate(this[i], i, this)) { return i; } } return -1; };

    and it will fix your issue

  19. traez commented on Sep 18, 2024

    @traez

    Compile Error Line 31: Char 32: error TS2550: Property 'findLastIndex' does not exist on type 'string[]'. Do you need to change your target library? Try changing the 'lib' compiler option to 'es2023' or later.

    Got above on my LeetCode solution https://leetcode.com/problems/increasing-decreasing-string

    MDN says

    "Baseline 2022 Newly available Since August 2022, this feature works across the latest devices and browser versions. This feature might not work in older devices or browsers."

    So I guess that's why. Leetcode yet to update their transpiler/compiler

  20. locked as resolved and limited conversation to collaborators on Oct 22, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

BugA bug in TypeScriptDomain: lib.d.tsThe issue relates to the different libraries shipped with TypeScriptEffort: CasualGood issue if you're already used to contributing to the codebase. Harder than "good first issue".Fix AvailableA PR has been opened for this issueHelp WantedYou can do this

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions