You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Add Array.prototype.findLast and Array.prototype.findLastIndex #48829
Wenlu Wang (@Kingwl) It’s your fault that Firefox doesn’t support this API? What?
Reacted by Joshua Chen, Nico Jansen, csha, Ricardo Fernández Serrata, Ian Kim, Roman Diadiushkin, Volodeccc, Jason Wang, blangley28, Nazario A. Ayala and 5 more
changed the title [-][lib] missing `Array.prototype.findLast` and `Array.prototype.findLastIndex`[/-][+]Add `Array.prototype.findLast` and `Array.prototype.findLastIndex`[/+]on Jun 6, 2022
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).
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.
Tried also updating to the latest Typyscript 5.1 build, no change.
Reacted by EgorVolfCyVers, Marko Väljaots and Orooj Tatiev
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.
Reacted by Evgeniia Osmakova, Oleksandr Shapovalenko, Gökhan, NedEX, Paul Baisley, Ivan Pandzic, Meysam Izadmehr, iMoses, shagag, Bruno Ruas De Pinho and 12 more
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.
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
Reacted by Daniel Lazar, Rafael Cesar Rodrigues de Andrade, Spicearth, Lonli-Lokli, Westbrook Johnson, Stanislav, Denoph, Vahid Mohammadi and Quackzoer
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.
"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
Activity
andrewbranch commentedon Apr 25, 2022
[Double checking with Daniel Rosenwasser (@DanielRosenwasser) that stage 3 is the only criteria for adding to lib.esnext]
DanielRosenwasser commentedon Apr 26, 2022
It is, but if I ask for stage 4 at an upcoming meeting we might as well add it to a stable version.
fatcerberus commentedon Apr 27, 2022
Seems weird that Firefox hasn’t implemented it yet, that’s a bit unfortunate.
Kingwl commentedon Apr 28, 2022
Sorry....My fault.
fatcerberus commentedon Apr 28, 2022
Wenlu Wang (@Kingwl) It’s your fault that Firefox doesn’t support this API? What?
DanielRosenwasser commentedon Jun 6, 2022
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.[-][lib] missing `Array.prototype.findLast` and `Array.prototype.findLastIndex`[/-][+]Add `Array.prototype.findLast` and `Array.prototype.findLastIndex`[/+]monikams commentedon Oct 12, 2022
With which version of typescript I could use the method findLast?
16 remaining items
Upgrade typescript to 5.0.x to use Array.findLast()
cristan commentedon Apr 13, 2023
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).BR0kEN- commentedon Apr 18, 2023
It works only in TS 5 and only when the
targetisESNext.juneate commentedon Apr 25, 2023
Incorrect, as you can see here:

As Sergii Bondarenko (@BR0kEN-) said, if you change the
targetin that environment, the issue disappears. But if you try to "Export" the example to CodeSandbox with the same settings, it triggers the issue again.Tried also updating to the latest Typyscript
5.1build, no change.Remove custom type annotation for `Array.prototype.findLast`
(focus-trap/src/global.d.ts) Remove custom type annotation for `Array…
(focus-trap/src/global.d.ts) Remove custom type annotation for `Array…
cristan commentedon Jun 26, 2023
findLast was introduced in EcmaScript 2023. However,
es2023isn't supported in Typescript 5. Maybe that's it?shakedhagag commentedon Sep 13, 2023
Is there any progress with this issue?
jacobbogers commentedon Oct 26, 2023
Is there any progress on this issue?
RyanCavanaugh commentedon Oct 26, 2023
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.cristan commentedon Dec 19, 2023
Ah, it indeed does work, but the problem is indeed that
findLastwas 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,
findLastdoes work when setting the target toesnext^_^In the handbook, you'll see that
es2023is 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 toes2023instead to this vague concept, but hey, it works.GoRRRRchik commentedon Feb 20, 2024
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
traez commentedon Sep 18, 2024
Got above on my LeetCode solution https://leetcode.com/problems/increasing-decreasing-string
MDN says
So I guess that's why. Leetcode yet to update their transpiler/compiler