Skip to content

Commit

Permalink
🤖 Pick PR #58951 (Add non-mutating Array methods to e...) into releas…
Browse files Browse the repository at this point in the history
…e-5.5 (#59405)

Co-authored-by: Daniel Rosenwasser <[email protected]>
  • Loading branch information
TypeScript Bot and DanielRosenwasser authored Aug 1, 2024
1 parent c8a7d58 commit 5270c59
Show file tree
Hide file tree
Showing 8 changed files with 801 additions and 0 deletions.
48 changes: 48 additions & 0 deletions src/compiler/utilities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1315,6 +1315,10 @@ export const getScriptTargetFeatures = /* @__PURE__ */ memoize((): ScriptTargetF
es2023: [
"findLastIndex",
"findLast",
"toReversed",
"toSorted",
"toSpliced",
"with",
],
})),
Iterator: new Map(Object.entries({
Expand Down Expand Up @@ -1592,6 +1596,10 @@ export const getScriptTargetFeatures = /* @__PURE__ */ memoize((): ScriptTargetF
es2023: [
"findLastIndex",
"findLast",
"toReversed",
"toSorted",
"toSpliced",
"with",
],
})),
Uint8Array: new Map(Object.entries({
Expand All @@ -1601,6 +1609,10 @@ export const getScriptTargetFeatures = /* @__PURE__ */ memoize((): ScriptTargetF
es2023: [
"findLastIndex",
"findLast",
"toReversed",
"toSorted",
"toSpliced",
"with",
],
})),
Uint8ClampedArray: new Map(Object.entries({
Expand All @@ -1610,6 +1622,10 @@ export const getScriptTargetFeatures = /* @__PURE__ */ memoize((): ScriptTargetF
es2023: [
"findLastIndex",
"findLast",
"toReversed",
"toSorted",
"toSpliced",
"with",
],
})),
Int16Array: new Map(Object.entries({
Expand All @@ -1619,6 +1635,10 @@ export const getScriptTargetFeatures = /* @__PURE__ */ memoize((): ScriptTargetF
es2023: [
"findLastIndex",
"findLast",
"toReversed",
"toSorted",
"toSpliced",
"with",
],
})),
Uint16Array: new Map(Object.entries({
Expand All @@ -1628,6 +1648,10 @@ export const getScriptTargetFeatures = /* @__PURE__ */ memoize((): ScriptTargetF
es2023: [
"findLastIndex",
"findLast",
"toReversed",
"toSorted",
"toSpliced",
"with",
],
})),
Int32Array: new Map(Object.entries({
Expand All @@ -1637,6 +1661,10 @@ export const getScriptTargetFeatures = /* @__PURE__ */ memoize((): ScriptTargetF
es2023: [
"findLastIndex",
"findLast",
"toReversed",
"toSorted",
"toSpliced",
"with",
],
})),
Uint32Array: new Map(Object.entries({
Expand All @@ -1646,6 +1674,10 @@ export const getScriptTargetFeatures = /* @__PURE__ */ memoize((): ScriptTargetF
es2023: [
"findLastIndex",
"findLast",
"toReversed",
"toSorted",
"toSpliced",
"with",
],
})),
Float32Array: new Map(Object.entries({
Expand All @@ -1655,6 +1687,10 @@ export const getScriptTargetFeatures = /* @__PURE__ */ memoize((): ScriptTargetF
es2023: [
"findLastIndex",
"findLast",
"toReversed",
"toSorted",
"toSpliced",
"with",
],
})),
Float64Array: new Map(Object.entries({
Expand All @@ -1664,6 +1700,10 @@ export const getScriptTargetFeatures = /* @__PURE__ */ memoize((): ScriptTargetF
es2023: [
"findLastIndex",
"findLast",
"toReversed",
"toSorted",
"toSpliced",
"with",
],
})),
BigInt64Array: new Map(Object.entries({
Expand All @@ -1674,6 +1714,10 @@ export const getScriptTargetFeatures = /* @__PURE__ */ memoize((): ScriptTargetF
es2023: [
"findLastIndex",
"findLast",
"toReversed",
"toSorted",
"toSpliced",
"with",
],
})),
BigUint64Array: new Map(Object.entries({
Expand All @@ -1684,6 +1728,10 @@ export const getScriptTargetFeatures = /* @__PURE__ */ memoize((): ScriptTargetF
es2023: [
"findLastIndex",
"findLast",
"toReversed",
"toSorted",
"toSpliced",
"with",
],
})),
Error: new Map(Object.entries({
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
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.
doYouNeedToChangeYourTargetLibraryES2023.ts(7,45): error TS7006: Parameter 'v' implicitly has an 'any' type.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.


==== doYouNeedToChangeYourTargetLibraryES2023.ts (13 errors) ====
export let array = [0, 2, 3, 4];

function somePredicate(x: any): boolean {
return x === 4;
}

export let lastIndex1 = array.findLastIndex(v => v === 4);
~~~~~~~~~~~~~
!!! 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.
~
!!! error TS7006: Parameter 'v' implicitly has an 'any' type.
export let lastIndex2 = array.findLastIndex(somePredicate);
~~~~~~~~~~~~~
!!! 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.

export let last1 = array.findLast(somePredicate);
~~~~~~~~
!!! 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.
export let last2 = array.findLast(somePredicate);
~~~~~~~~
!!! 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.

export let sorted = array.toSorted();
~~~~~~~~
!!! 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.

export let spliced1 = array.toSpliced(2);
~~~~~~~~~
!!! 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.
export let spliced2 = array.toSpliced(2, 1);
~~~~~~~~~
!!! 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.
export let spliced3 = array.toSpliced(2, 1, 4, 5, 6, 7);
~~~~~~~~~
!!! 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.
export let spliced4 = array.toSpliced(2, undefined);
~~~~~~~~~
!!! 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.
export let spliced5 = array.toSpliced(2, undefined, 4, 5, 6, 7);
~~~~~~~~~
!!! 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.

export let startsWithOne = array.with(0, 1);
~~~~
!!! 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.
export let inTheEnd = array.with(-1, 1);
~~~~
!!! 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 number Diff line number Diff line change
@@ -0,0 +1,69 @@
//// [tests/cases/compiler/doYouNeedToChangeYourTargetLibraryES2023.ts] ////

=== doYouNeedToChangeYourTargetLibraryES2023.ts ===
export let array = [0, 2, 3, 4];
>array : Symbol(array, Decl(doYouNeedToChangeYourTargetLibraryES2023.ts, 0, 10))

function somePredicate(x: any): boolean {
>somePredicate : Symbol(somePredicate, Decl(doYouNeedToChangeYourTargetLibraryES2023.ts, 0, 32))
>x : Symbol(x, Decl(doYouNeedToChangeYourTargetLibraryES2023.ts, 2, 23))

return x === 4;
>x : Symbol(x, Decl(doYouNeedToChangeYourTargetLibraryES2023.ts, 2, 23))
}

export let lastIndex1 = array.findLastIndex(v => v === 4);
>lastIndex1 : Symbol(lastIndex1, Decl(doYouNeedToChangeYourTargetLibraryES2023.ts, 6, 10))
>array : Symbol(array, Decl(doYouNeedToChangeYourTargetLibraryES2023.ts, 0, 10))
>v : Symbol(v, Decl(doYouNeedToChangeYourTargetLibraryES2023.ts, 6, 44))
>v : Symbol(v, Decl(doYouNeedToChangeYourTargetLibraryES2023.ts, 6, 44))

export let lastIndex2 = array.findLastIndex(somePredicate);
>lastIndex2 : Symbol(lastIndex2, Decl(doYouNeedToChangeYourTargetLibraryES2023.ts, 7, 10))
>array : Symbol(array, Decl(doYouNeedToChangeYourTargetLibraryES2023.ts, 0, 10))
>somePredicate : Symbol(somePredicate, Decl(doYouNeedToChangeYourTargetLibraryES2023.ts, 0, 32))

export let last1 = array.findLast(somePredicate);
>last1 : Symbol(last1, Decl(doYouNeedToChangeYourTargetLibraryES2023.ts, 9, 10))
>array : Symbol(array, Decl(doYouNeedToChangeYourTargetLibraryES2023.ts, 0, 10))
>somePredicate : Symbol(somePredicate, Decl(doYouNeedToChangeYourTargetLibraryES2023.ts, 0, 32))

export let last2 = array.findLast(somePredicate);
>last2 : Symbol(last2, Decl(doYouNeedToChangeYourTargetLibraryES2023.ts, 10, 10))
>array : Symbol(array, Decl(doYouNeedToChangeYourTargetLibraryES2023.ts, 0, 10))
>somePredicate : Symbol(somePredicate, Decl(doYouNeedToChangeYourTargetLibraryES2023.ts, 0, 32))

export let sorted = array.toSorted();
>sorted : Symbol(sorted, Decl(doYouNeedToChangeYourTargetLibraryES2023.ts, 12, 10))
>array : Symbol(array, Decl(doYouNeedToChangeYourTargetLibraryES2023.ts, 0, 10))

export let spliced1 = array.toSpliced(2);
>spliced1 : Symbol(spliced1, Decl(doYouNeedToChangeYourTargetLibraryES2023.ts, 14, 10))
>array : Symbol(array, Decl(doYouNeedToChangeYourTargetLibraryES2023.ts, 0, 10))

export let spliced2 = array.toSpliced(2, 1);
>spliced2 : Symbol(spliced2, Decl(doYouNeedToChangeYourTargetLibraryES2023.ts, 15, 10))
>array : Symbol(array, Decl(doYouNeedToChangeYourTargetLibraryES2023.ts, 0, 10))

export let spliced3 = array.toSpliced(2, 1, 4, 5, 6, 7);
>spliced3 : Symbol(spliced3, Decl(doYouNeedToChangeYourTargetLibraryES2023.ts, 16, 10))
>array : Symbol(array, Decl(doYouNeedToChangeYourTargetLibraryES2023.ts, 0, 10))

export let spliced4 = array.toSpliced(2, undefined);
>spliced4 : Symbol(spliced4, Decl(doYouNeedToChangeYourTargetLibraryES2023.ts, 17, 10))
>array : Symbol(array, Decl(doYouNeedToChangeYourTargetLibraryES2023.ts, 0, 10))
>undefined : Symbol(undefined)

export let spliced5 = array.toSpliced(2, undefined, 4, 5, 6, 7);
>spliced5 : Symbol(spliced5, Decl(doYouNeedToChangeYourTargetLibraryES2023.ts, 18, 10))
>array : Symbol(array, Decl(doYouNeedToChangeYourTargetLibraryES2023.ts, 0, 10))
>undefined : Symbol(undefined)

export let startsWithOne = array.with(0, 1);
>startsWithOne : Symbol(startsWithOne, Decl(doYouNeedToChangeYourTargetLibraryES2023.ts, 20, 10))
>array : Symbol(array, Decl(doYouNeedToChangeYourTargetLibraryES2023.ts, 0, 10))

export let inTheEnd = array.with(-1, 1);
>inTheEnd : Symbol(inTheEnd, Decl(doYouNeedToChangeYourTargetLibraryES2023.ts, 21, 10))
>array : Symbol(array, Decl(doYouNeedToChangeYourTargetLibraryES2023.ts, 0, 10))

Loading

0 comments on commit 5270c59

Please sign in to comment.