Skip to content

Commit 298371e

Browse files
DanielRosenwassertypescript-bot
authored andcommitted
Add non-mutating Array methods to es2023 in the lib/target suggestion list (#58951)
1 parent c8a7d58 commit 298371e

8 files changed

+801
-0
lines changed

src/compiler/utilities.ts

+48
Original file line numberDiff line numberDiff line change
@@ -1315,6 +1315,10 @@ export const getScriptTargetFeatures = /* @__PURE__ */ memoize((): ScriptTargetF
13151315
es2023: [
13161316
"findLastIndex",
13171317
"findLast",
1318+
"toReversed",
1319+
"toSorted",
1320+
"toSpliced",
1321+
"with",
13181322
],
13191323
})),
13201324
Iterator: new Map(Object.entries({
@@ -1592,6 +1596,10 @@ export const getScriptTargetFeatures = /* @__PURE__ */ memoize((): ScriptTargetF
15921596
es2023: [
15931597
"findLastIndex",
15941598
"findLast",
1599+
"toReversed",
1600+
"toSorted",
1601+
"toSpliced",
1602+
"with",
15951603
],
15961604
})),
15971605
Uint8Array: new Map(Object.entries({
@@ -1601,6 +1609,10 @@ export const getScriptTargetFeatures = /* @__PURE__ */ memoize((): ScriptTargetF
16011609
es2023: [
16021610
"findLastIndex",
16031611
"findLast",
1612+
"toReversed",
1613+
"toSorted",
1614+
"toSpliced",
1615+
"with",
16041616
],
16051617
})),
16061618
Uint8ClampedArray: new Map(Object.entries({
@@ -1610,6 +1622,10 @@ export const getScriptTargetFeatures = /* @__PURE__ */ memoize((): ScriptTargetF
16101622
es2023: [
16111623
"findLastIndex",
16121624
"findLast",
1625+
"toReversed",
1626+
"toSorted",
1627+
"toSpliced",
1628+
"with",
16131629
],
16141630
})),
16151631
Int16Array: new Map(Object.entries({
@@ -1619,6 +1635,10 @@ export const getScriptTargetFeatures = /* @__PURE__ */ memoize((): ScriptTargetF
16191635
es2023: [
16201636
"findLastIndex",
16211637
"findLast",
1638+
"toReversed",
1639+
"toSorted",
1640+
"toSpliced",
1641+
"with",
16221642
],
16231643
})),
16241644
Uint16Array: new Map(Object.entries({
@@ -1628,6 +1648,10 @@ export const getScriptTargetFeatures = /* @__PURE__ */ memoize((): ScriptTargetF
16281648
es2023: [
16291649
"findLastIndex",
16301650
"findLast",
1651+
"toReversed",
1652+
"toSorted",
1653+
"toSpliced",
1654+
"with",
16311655
],
16321656
})),
16331657
Int32Array: new Map(Object.entries({
@@ -1637,6 +1661,10 @@ export const getScriptTargetFeatures = /* @__PURE__ */ memoize((): ScriptTargetF
16371661
es2023: [
16381662
"findLastIndex",
16391663
"findLast",
1664+
"toReversed",
1665+
"toSorted",
1666+
"toSpliced",
1667+
"with",
16401668
],
16411669
})),
16421670
Uint32Array: new Map(Object.entries({
@@ -1646,6 +1674,10 @@ export const getScriptTargetFeatures = /* @__PURE__ */ memoize((): ScriptTargetF
16461674
es2023: [
16471675
"findLastIndex",
16481676
"findLast",
1677+
"toReversed",
1678+
"toSorted",
1679+
"toSpliced",
1680+
"with",
16491681
],
16501682
})),
16511683
Float32Array: new Map(Object.entries({
@@ -1655,6 +1687,10 @@ export const getScriptTargetFeatures = /* @__PURE__ */ memoize((): ScriptTargetF
16551687
es2023: [
16561688
"findLastIndex",
16571689
"findLast",
1690+
"toReversed",
1691+
"toSorted",
1692+
"toSpliced",
1693+
"with",
16581694
],
16591695
})),
16601696
Float64Array: new Map(Object.entries({
@@ -1664,6 +1700,10 @@ export const getScriptTargetFeatures = /* @__PURE__ */ memoize((): ScriptTargetF
16641700
es2023: [
16651701
"findLastIndex",
16661702
"findLast",
1703+
"toReversed",
1704+
"toSorted",
1705+
"toSpliced",
1706+
"with",
16671707
],
16681708
})),
16691709
BigInt64Array: new Map(Object.entries({
@@ -1674,6 +1714,10 @@ export const getScriptTargetFeatures = /* @__PURE__ */ memoize((): ScriptTargetF
16741714
es2023: [
16751715
"findLastIndex",
16761716
"findLast",
1717+
"toReversed",
1718+
"toSorted",
1719+
"toSpliced",
1720+
"with",
16771721
],
16781722
})),
16791723
BigUint64Array: new Map(Object.entries({
@@ -1684,6 +1728,10 @@ export const getScriptTargetFeatures = /* @__PURE__ */ memoize((): ScriptTargetF
16841728
es2023: [
16851729
"findLastIndex",
16861730
"findLast",
1731+
"toReversed",
1732+
"toSorted",
1733+
"toSpliced",
1734+
"with",
16871735
],
16881736
})),
16891737
Error: new Map(Object.entries({
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
doYouNeedToChangeYourTargetLibraryES2023.ts(7,31): error TS2550: Property 'findLastIndex' does not exist on type 'number[]'. Do you need to change your target library? Try changing the 'lib' compiler option to 'es2023' or later.
2+
doYouNeedToChangeYourTargetLibraryES2023.ts(7,45): error TS7006: Parameter 'v' implicitly has an 'any' type.
3+
doYouNeedToChangeYourTargetLibraryES2023.ts(8,31): error TS2550: Property 'findLastIndex' does not exist on type 'number[]'. Do you need to change your target library? Try changing the 'lib' compiler option to 'es2023' or later.
4+
doYouNeedToChangeYourTargetLibraryES2023.ts(10,26): error TS2550: Property 'findLast' does not exist on type 'number[]'. Do you need to change your target library? Try changing the 'lib' compiler option to 'es2023' or later.
5+
doYouNeedToChangeYourTargetLibraryES2023.ts(11,26): error TS2550: Property 'findLast' does not exist on type 'number[]'. Do you need to change your target library? Try changing the 'lib' compiler option to 'es2023' or later.
6+
doYouNeedToChangeYourTargetLibraryES2023.ts(13,27): error TS2550: Property 'toSorted' does not exist on type 'number[]'. Do you need to change your target library? Try changing the 'lib' compiler option to 'es2023' or later.
7+
doYouNeedToChangeYourTargetLibraryES2023.ts(15,29): error TS2550: Property 'toSpliced' does not exist on type 'number[]'. Do you need to change your target library? Try changing the 'lib' compiler option to 'es2023' or later.
8+
doYouNeedToChangeYourTargetLibraryES2023.ts(16,29): error TS2550: Property 'toSpliced' does not exist on type 'number[]'. Do you need to change your target library? Try changing the 'lib' compiler option to 'es2023' or later.
9+
doYouNeedToChangeYourTargetLibraryES2023.ts(17,29): error TS2550: Property 'toSpliced' does not exist on type 'number[]'. Do you need to change your target library? Try changing the 'lib' compiler option to 'es2023' or later.
10+
doYouNeedToChangeYourTargetLibraryES2023.ts(18,29): error TS2550: Property 'toSpliced' does not exist on type 'number[]'. Do you need to change your target library? Try changing the 'lib' compiler option to 'es2023' or later.
11+
doYouNeedToChangeYourTargetLibraryES2023.ts(19,29): error TS2550: Property 'toSpliced' does not exist on type 'number[]'. Do you need to change your target library? Try changing the 'lib' compiler option to 'es2023' or later.
12+
doYouNeedToChangeYourTargetLibraryES2023.ts(21,34): error TS2550: Property 'with' does not exist on type 'number[]'. Do you need to change your target library? Try changing the 'lib' compiler option to 'es2023' or later.
13+
doYouNeedToChangeYourTargetLibraryES2023.ts(22,29): error TS2550: Property 'with' does not exist on type 'number[]'. Do you need to change your target library? Try changing the 'lib' compiler option to 'es2023' or later.
14+
15+
16+
==== doYouNeedToChangeYourTargetLibraryES2023.ts (13 errors) ====
17+
export let array = [0, 2, 3, 4];
18+
19+
function somePredicate(x: any): boolean {
20+
return x === 4;
21+
}
22+
23+
export let lastIndex1 = array.findLastIndex(v => v === 4);
24+
~~~~~~~~~~~~~
25+
!!! error TS2550: Property 'findLastIndex' does not exist on type 'number[]'. Do you need to change your target library? Try changing the 'lib' compiler option to 'es2023' or later.
26+
~
27+
!!! error TS7006: Parameter 'v' implicitly has an 'any' type.
28+
export let lastIndex2 = array.findLastIndex(somePredicate);
29+
~~~~~~~~~~~~~
30+
!!! error TS2550: Property 'findLastIndex' does not exist on type 'number[]'. Do you need to change your target library? Try changing the 'lib' compiler option to 'es2023' or later.
31+
32+
export let last1 = array.findLast(somePredicate);
33+
~~~~~~~~
34+
!!! error TS2550: Property 'findLast' does not exist on type 'number[]'. Do you need to change your target library? Try changing the 'lib' compiler option to 'es2023' or later.
35+
export let last2 = array.findLast(somePredicate);
36+
~~~~~~~~
37+
!!! error TS2550: Property 'findLast' does not exist on type 'number[]'. Do you need to change your target library? Try changing the 'lib' compiler option to 'es2023' or later.
38+
39+
export let sorted = array.toSorted();
40+
~~~~~~~~
41+
!!! error TS2550: Property 'toSorted' does not exist on type 'number[]'. Do you need to change your target library? Try changing the 'lib' compiler option to 'es2023' or later.
42+
43+
export let spliced1 = array.toSpliced(2);
44+
~~~~~~~~~
45+
!!! error TS2550: Property 'toSpliced' does not exist on type 'number[]'. Do you need to change your target library? Try changing the 'lib' compiler option to 'es2023' or later.
46+
export let spliced2 = array.toSpliced(2, 1);
47+
~~~~~~~~~
48+
!!! error TS2550: Property 'toSpliced' does not exist on type 'number[]'. Do you need to change your target library? Try changing the 'lib' compiler option to 'es2023' or later.
49+
export let spliced3 = array.toSpliced(2, 1, 4, 5, 6, 7);
50+
~~~~~~~~~
51+
!!! error TS2550: Property 'toSpliced' does not exist on type 'number[]'. Do you need to change your target library? Try changing the 'lib' compiler option to 'es2023' or later.
52+
export let spliced4 = array.toSpliced(2, undefined);
53+
~~~~~~~~~
54+
!!! error TS2550: Property 'toSpliced' does not exist on type 'number[]'. Do you need to change your target library? Try changing the 'lib' compiler option to 'es2023' or later.
55+
export let spliced5 = array.toSpliced(2, undefined, 4, 5, 6, 7);
56+
~~~~~~~~~
57+
!!! error TS2550: Property 'toSpliced' does not exist on type 'number[]'. Do you need to change your target library? Try changing the 'lib' compiler option to 'es2023' or later.
58+
59+
export let startsWithOne = array.with(0, 1);
60+
~~~~
61+
!!! error TS2550: Property 'with' does not exist on type 'number[]'. Do you need to change your target library? Try changing the 'lib' compiler option to 'es2023' or later.
62+
export let inTheEnd = array.with(-1, 1);
63+
~~~~
64+
!!! error TS2550: Property 'with' does not exist on type 'number[]'. Do you need to change your target library? Try changing the 'lib' compiler option to 'es2023' or later.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
//// [tests/cases/compiler/doYouNeedToChangeYourTargetLibraryES2023.ts] ////
2+
3+
=== doYouNeedToChangeYourTargetLibraryES2023.ts ===
4+
export let array = [0, 2, 3, 4];
5+
>array : Symbol(array, Decl(doYouNeedToChangeYourTargetLibraryES2023.ts, 0, 10))
6+
7+
function somePredicate(x: any): boolean {
8+
>somePredicate : Symbol(somePredicate, Decl(doYouNeedToChangeYourTargetLibraryES2023.ts, 0, 32))
9+
>x : Symbol(x, Decl(doYouNeedToChangeYourTargetLibraryES2023.ts, 2, 23))
10+
11+
return x === 4;
12+
>x : Symbol(x, Decl(doYouNeedToChangeYourTargetLibraryES2023.ts, 2, 23))
13+
}
14+
15+
export let lastIndex1 = array.findLastIndex(v => v === 4);
16+
>lastIndex1 : Symbol(lastIndex1, Decl(doYouNeedToChangeYourTargetLibraryES2023.ts, 6, 10))
17+
>array : Symbol(array, Decl(doYouNeedToChangeYourTargetLibraryES2023.ts, 0, 10))
18+
>v : Symbol(v, Decl(doYouNeedToChangeYourTargetLibraryES2023.ts, 6, 44))
19+
>v : Symbol(v, Decl(doYouNeedToChangeYourTargetLibraryES2023.ts, 6, 44))
20+
21+
export let lastIndex2 = array.findLastIndex(somePredicate);
22+
>lastIndex2 : Symbol(lastIndex2, Decl(doYouNeedToChangeYourTargetLibraryES2023.ts, 7, 10))
23+
>array : Symbol(array, Decl(doYouNeedToChangeYourTargetLibraryES2023.ts, 0, 10))
24+
>somePredicate : Symbol(somePredicate, Decl(doYouNeedToChangeYourTargetLibraryES2023.ts, 0, 32))
25+
26+
export let last1 = array.findLast(somePredicate);
27+
>last1 : Symbol(last1, Decl(doYouNeedToChangeYourTargetLibraryES2023.ts, 9, 10))
28+
>array : Symbol(array, Decl(doYouNeedToChangeYourTargetLibraryES2023.ts, 0, 10))
29+
>somePredicate : Symbol(somePredicate, Decl(doYouNeedToChangeYourTargetLibraryES2023.ts, 0, 32))
30+
31+
export let last2 = array.findLast(somePredicate);
32+
>last2 : Symbol(last2, Decl(doYouNeedToChangeYourTargetLibraryES2023.ts, 10, 10))
33+
>array : Symbol(array, Decl(doYouNeedToChangeYourTargetLibraryES2023.ts, 0, 10))
34+
>somePredicate : Symbol(somePredicate, Decl(doYouNeedToChangeYourTargetLibraryES2023.ts, 0, 32))
35+
36+
export let sorted = array.toSorted();
37+
>sorted : Symbol(sorted, Decl(doYouNeedToChangeYourTargetLibraryES2023.ts, 12, 10))
38+
>array : Symbol(array, Decl(doYouNeedToChangeYourTargetLibraryES2023.ts, 0, 10))
39+
40+
export let spliced1 = array.toSpliced(2);
41+
>spliced1 : Symbol(spliced1, Decl(doYouNeedToChangeYourTargetLibraryES2023.ts, 14, 10))
42+
>array : Symbol(array, Decl(doYouNeedToChangeYourTargetLibraryES2023.ts, 0, 10))
43+
44+
export let spliced2 = array.toSpliced(2, 1);
45+
>spliced2 : Symbol(spliced2, Decl(doYouNeedToChangeYourTargetLibraryES2023.ts, 15, 10))
46+
>array : Symbol(array, Decl(doYouNeedToChangeYourTargetLibraryES2023.ts, 0, 10))
47+
48+
export let spliced3 = array.toSpliced(2, 1, 4, 5, 6, 7);
49+
>spliced3 : Symbol(spliced3, Decl(doYouNeedToChangeYourTargetLibraryES2023.ts, 16, 10))
50+
>array : Symbol(array, Decl(doYouNeedToChangeYourTargetLibraryES2023.ts, 0, 10))
51+
52+
export let spliced4 = array.toSpliced(2, undefined);
53+
>spliced4 : Symbol(spliced4, Decl(doYouNeedToChangeYourTargetLibraryES2023.ts, 17, 10))
54+
>array : Symbol(array, Decl(doYouNeedToChangeYourTargetLibraryES2023.ts, 0, 10))
55+
>undefined : Symbol(undefined)
56+
57+
export let spliced5 = array.toSpliced(2, undefined, 4, 5, 6, 7);
58+
>spliced5 : Symbol(spliced5, Decl(doYouNeedToChangeYourTargetLibraryES2023.ts, 18, 10))
59+
>array : Symbol(array, Decl(doYouNeedToChangeYourTargetLibraryES2023.ts, 0, 10))
60+
>undefined : Symbol(undefined)
61+
62+
export let startsWithOne = array.with(0, 1);
63+
>startsWithOne : Symbol(startsWithOne, Decl(doYouNeedToChangeYourTargetLibraryES2023.ts, 20, 10))
64+
>array : Symbol(array, Decl(doYouNeedToChangeYourTargetLibraryES2023.ts, 0, 10))
65+
66+
export let inTheEnd = array.with(-1, 1);
67+
>inTheEnd : Symbol(inTheEnd, Decl(doYouNeedToChangeYourTargetLibraryES2023.ts, 21, 10))
68+
>array : Symbol(array, Decl(doYouNeedToChangeYourTargetLibraryES2023.ts, 0, 10))
69+

0 commit comments

Comments
 (0)