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

Fix for Issue 61081 #61221

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions src/lib/es5.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1375,14 +1375,20 @@ interface Array<T> {
/**
* Removes elements from an array and, if necessary, inserts new elements in their place, returning the deleted elements.
* @param start The zero-based location in the array from which to start removing elements.
* @param deleteCount The number of elements to remove.
* @param deleteCount The number of elements to remove. Omitting this argument will remove all elements from the start
* paramater location to end of the array. If value of this argument is either a negative number, zero, undefined, or a type
* that cannot be coverted to an integer, the function will evaluate the argument as zero and not remove any elements.
* @returns An array containing the elements that were deleted.
*/
splice(start: number, deleteCount?: number): T[];
/**
* Removes elements from an array and, if necessary, inserts new elements in their place, returning the deleted elements.
* @param start The zero-based location in the array from which to start removing elements.
* @param deleteCount The number of elements to remove.
* @param deleteCount The number of elements to remove. If value of this argument is either a negative number, zero,
* undefined, or a type that cannot be coverted to an integer, the function will evaluate the argument as zero and
* not remove any elements.
* Note: If the deleteCount argument is left empty between the start and items arguments, it will not be evaluated as
* an omission. Instead, it will be evaluated as undefined, which will be evaluated as zero.
* @param items Elements to insert into the array in place of the deleted elements.
* @returns An array containing the elements that were deleted.
*/
Expand Down
66 changes: 66 additions & 0 deletions tests/baselines/reference/arraySpliceParamDescription.errors.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
arraySpliceParamDescription.ts(12,34): error TS2769: No overload matches this call.
Overload 1 of 2, '(start: number, deleteCount?: number): string[]', gave the following error.
Argument of type 'string' is not assignable to parameter of type 'number'.
Overload 2 of 2, '(start: number, deleteCount: number, ...items: string[]): string[]', gave the following error.
Argument of type 'string' is not assignable to parameter of type 'number'.
arraySpliceParamDescription.ts(32,34): error TS1135: Argument expression expected.
arraySpliceParamDescription.ts(32,36): error TS2345: Argument of type 'string' is not assignable to parameter of type 'number'.
arraySpliceParamDescription.ts(34,34): error TS2345: Argument of type 'string' is not assignable to parameter of type 'number'.


==== arraySpliceParamDescription.ts (4 errors) ====
// @target es5

export function isEmptyArr(l: { length: number }) {
return l.length === 0
}

var arrA : string[]
arrA = ["a", "b", "c", "d", "e", "f", "g"]

// deleteCount param: undefined | NaN | 0 | -int; no elements removed
var undefSplice1 = arrA.splice(2, undefined) // OK
var charSplice1 = arrA.splice(2, "a") // expect error
~~~
!!! error TS2769: No overload matches this call.
!!! error TS2769: Overload 1 of 2, '(start: number, deleteCount?: number): string[]', gave the following error.
!!! error TS2769: Argument of type 'string' is not assignable to parameter of type 'number'.
!!! error TS2769: Overload 2 of 2, '(start: number, deleteCount: number, ...items: string[]): string[]', gave the following error.
!!! error TS2769: Argument of type 'string' is not assignable to parameter of type 'number'.
var naNSplice1 = arrA.splice(2, NaN) // OK
var zeroSplice1 = arrA.splice(2, 0) // OK
var negSplice1 = arrA.splice(2, -2) // OK and expect arrA = ["a", "b", "c", "d", "e", "f", "g"]

// deleteCount param omitted; All elements after start param are removed
var omitSplice1 = arrA.splice(2,) // OK expect arrA = ["a", "b"]

// testing the splice arrays are empty
isEmptyArr(undefSplice1) // OK and true
isEmptyArr(charSplice1) // OK and true
isEmptyArr(naNSplice1) // OK and true
isEmptyArr(zeroSplice1) // OK and true
isEmptyArr(negSplice1) // OK and true
isEmptyArr(omitSplice1) // OK and false. length of removed elements is 5

var arrB : string[]
arrB = ["a", "b", "c", "d", "e", "f", "g"]

var undefSplice2 = arrB.splice(2, undefined, "h", "i") // expect error and arrB = ["a", "b", "h", "i", "e", "f", "g"]
var omitSplice2 = arrB.splice(2, , "j", "k") // expect error and arrB = ["a", "b", "j", "k", "e", "f", "g"]
~
!!! error TS1135: Argument expression expected.
~~~
!!! error TS2345: Argument of type 'string' is not assignable to parameter of type 'number'.
var naNSplice2 = arrB.splice(2, NaN, "l", "m") // OK and arrB = ["a", "b", "l", "m", "e", "f", "g"]
var charSplice2 = arrB.splice(2, "a", "n", "o") // expect error and arrB = ["a", "b", "n", "o", "e", "f", "g"]
~~~
!!! error TS2345: Argument of type 'string' is not assignable to parameter of type 'number'.
var zeroSplice2 = arrB.splice(2, 0, "p", "q") // OK and arrB = ["a", "b", "p", "q", "e", "f", "g"]
var negSplice2 = arrB.splice(2, -2, "r", "s") // OK and arrB = ["a", "b", "r", "s", "e", "f", "g"]

isEmptyArr(undefSplice2) // OK and true
isEmptyArr(omitSplice2) // OK and true
isEmptyArr(naNSplice2) // OK and true
isEmptyArr(charSplice2) // OK and true
isEmptyArr(zeroSplice2) // OK and true
isEmptyArr(negSplice2) // OK and true
86 changes: 86 additions & 0 deletions tests/baselines/reference/arraySpliceParamDescription.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
//// [tests/cases/compiler/arraySpliceParamDescription.ts] ////

//// [arraySpliceParamDescription.ts]
// @target es5

export function isEmptyArr(l: { length: number }) {
return l.length === 0
}

var arrA : string[]
arrA = ["a", "b", "c", "d", "e", "f", "g"]

// deleteCount param: undefined | NaN | 0 | -int; no elements removed
var undefSplice1 = arrA.splice(2, undefined) // OK
var charSplice1 = arrA.splice(2, "a") // expect error
var naNSplice1 = arrA.splice(2, NaN) // OK
var zeroSplice1 = arrA.splice(2, 0) // OK
var negSplice1 = arrA.splice(2, -2) // OK and expect arrA = ["a", "b", "c", "d", "e", "f", "g"]

// deleteCount param omitted; All elements after start param are removed
var omitSplice1 = arrA.splice(2,) // OK expect arrA = ["a", "b"]

// testing the splice arrays are empty
isEmptyArr(undefSplice1) // OK and true
isEmptyArr(charSplice1) // OK and true
isEmptyArr(naNSplice1) // OK and true
isEmptyArr(zeroSplice1) // OK and true
isEmptyArr(negSplice1) // OK and true
isEmptyArr(omitSplice1) // OK and false. length of removed elements is 5

var arrB : string[]
arrB = ["a", "b", "c", "d", "e", "f", "g"]

var undefSplice2 = arrB.splice(2, undefined, "h", "i") // expect error and arrB = ["a", "b", "h", "i", "e", "f", "g"]
var omitSplice2 = arrB.splice(2, , "j", "k") // expect error and arrB = ["a", "b", "j", "k", "e", "f", "g"]
var naNSplice2 = arrB.splice(2, NaN, "l", "m") // OK and arrB = ["a", "b", "l", "m", "e", "f", "g"]
var charSplice2 = arrB.splice(2, "a", "n", "o") // expect error and arrB = ["a", "b", "n", "o", "e", "f", "g"]
var zeroSplice2 = arrB.splice(2, 0, "p", "q") // OK and arrB = ["a", "b", "p", "q", "e", "f", "g"]
var negSplice2 = arrB.splice(2, -2, "r", "s") // OK and arrB = ["a", "b", "r", "s", "e", "f", "g"]

isEmptyArr(undefSplice2) // OK and true
isEmptyArr(omitSplice2) // OK and true
isEmptyArr(naNSplice2) // OK and true
isEmptyArr(charSplice2) // OK and true
isEmptyArr(zeroSplice2) // OK and true
isEmptyArr(negSplice2) // OK and true

//// [arraySpliceParamDescription.js]
"use strict";
// @target es5
Object.defineProperty(exports, "__esModule", { value: true });
exports.isEmptyArr = isEmptyArr;
function isEmptyArr(l) {
return l.length === 0;
}
var arrA;
arrA = ["a", "b", "c", "d", "e", "f", "g"];
// deleteCount param: undefined | NaN | 0 | -int; no elements removed
var undefSplice1 = arrA.splice(2, undefined); // OK
var charSplice1 = arrA.splice(2, "a"); // expect error
var naNSplice1 = arrA.splice(2, NaN); // OK
var zeroSplice1 = arrA.splice(2, 0); // OK
var negSplice1 = arrA.splice(2, -2); // OK and expect arrA = ["a", "b", "c", "d", "e", "f", "g"]
// deleteCount param omitted; All elements after start param are removed
var omitSplice1 = arrA.splice(2); // OK expect arrA = ["a", "b"]
// testing the splice arrays are empty
isEmptyArr(undefSplice1); // OK and true
isEmptyArr(charSplice1); // OK and true
isEmptyArr(naNSplice1); // OK and true
isEmptyArr(zeroSplice1); // OK and true
isEmptyArr(negSplice1); // OK and true
isEmptyArr(omitSplice1); // OK and false. length of removed elements is 5
var arrB;
arrB = ["a", "b", "c", "d", "e", "f", "g"];
var undefSplice2 = arrB.splice(2, undefined, "h", "i"); // expect error and arrB = ["a", "b", "h", "i", "e", "f", "g"]
var omitSplice2 = arrB.splice(2, "j", "k"); // expect error and arrB = ["a", "b", "j", "k", "e", "f", "g"]
var naNSplice2 = arrB.splice(2, NaN, "l", "m"); // OK and arrB = ["a", "b", "l", "m", "e", "f", "g"]
var charSplice2 = arrB.splice(2, "a", "n", "o"); // expect error and arrB = ["a", "b", "n", "o", "e", "f", "g"]
var zeroSplice2 = arrB.splice(2, 0, "p", "q"); // OK and arrB = ["a", "b", "p", "q", "e", "f", "g"]
var negSplice2 = arrB.splice(2, -2, "r", "s"); // OK and arrB = ["a", "b", "r", "s", "e", "f", "g"]
isEmptyArr(undefSplice2); // OK and true
isEmptyArr(omitSplice2); // OK and true
isEmptyArr(naNSplice2); // OK and true
isEmptyArr(charSplice2); // OK and true
isEmptyArr(zeroSplice2); // OK and true
isEmptyArr(negSplice2); // OK and true
155 changes: 155 additions & 0 deletions tests/baselines/reference/arraySpliceParamDescription.symbols
Original file line number Diff line number Diff line change
@@ -0,0 +1,155 @@
//// [tests/cases/compiler/arraySpliceParamDescription.ts] ////

=== arraySpliceParamDescription.ts ===
// @target es5

export function isEmptyArr(l: { length: number }) {
>isEmptyArr : Symbol(isEmptyArr, Decl(arraySpliceParamDescription.ts, 0, 0))
>l : Symbol(l, Decl(arraySpliceParamDescription.ts, 2, 27))
>length : Symbol(length, Decl(arraySpliceParamDescription.ts, 2, 31))

return l.length === 0
>l.length : Symbol(length, Decl(arraySpliceParamDescription.ts, 2, 31))
>l : Symbol(l, Decl(arraySpliceParamDescription.ts, 2, 27))
>length : Symbol(length, Decl(arraySpliceParamDescription.ts, 2, 31))
}

var arrA : string[]
>arrA : Symbol(arrA, Decl(arraySpliceParamDescription.ts, 6, 3))

arrA = ["a", "b", "c", "d", "e", "f", "g"]
>arrA : Symbol(arrA, Decl(arraySpliceParamDescription.ts, 6, 3))

// deleteCount param: undefined | NaN | 0 | -int; no elements removed
var undefSplice1 = arrA.splice(2, undefined) // OK
>undefSplice1 : Symbol(undefSplice1, Decl(arraySpliceParamDescription.ts, 10, 3))
>arrA.splice : Symbol(Array.splice, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --))
>arrA : Symbol(arrA, Decl(arraySpliceParamDescription.ts, 6, 3))
>splice : Symbol(Array.splice, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --))
>undefined : Symbol(undefined)

var charSplice1 = arrA.splice(2, "a") // expect error
>charSplice1 : Symbol(charSplice1, Decl(arraySpliceParamDescription.ts, 11, 3))
>arrA.splice : Symbol(Array.splice, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --))
>arrA : Symbol(arrA, Decl(arraySpliceParamDescription.ts, 6, 3))
>splice : Symbol(Array.splice, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --))

var naNSplice1 = arrA.splice(2, NaN) // OK
>naNSplice1 : Symbol(naNSplice1, Decl(arraySpliceParamDescription.ts, 12, 3))
>arrA.splice : Symbol(Array.splice, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --))
>arrA : Symbol(arrA, Decl(arraySpliceParamDescription.ts, 6, 3))
>splice : Symbol(Array.splice, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --))
>NaN : Symbol(NaN, Decl(lib.es5.d.ts, --, --))

var zeroSplice1 = arrA.splice(2, 0) // OK
>zeroSplice1 : Symbol(zeroSplice1, Decl(arraySpliceParamDescription.ts, 13, 3))
>arrA.splice : Symbol(Array.splice, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --))
>arrA : Symbol(arrA, Decl(arraySpliceParamDescription.ts, 6, 3))
>splice : Symbol(Array.splice, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --))

var negSplice1 = arrA.splice(2, -2) // OK and expect arrA = ["a", "b", "c", "d", "e", "f", "g"]
>negSplice1 : Symbol(negSplice1, Decl(arraySpliceParamDescription.ts, 14, 3))
>arrA.splice : Symbol(Array.splice, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --))
>arrA : Symbol(arrA, Decl(arraySpliceParamDescription.ts, 6, 3))
>splice : Symbol(Array.splice, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --))

// deleteCount param omitted; All elements after start param are removed
var omitSplice1 = arrA.splice(2,) // OK expect arrA = ["a", "b"]
>omitSplice1 : Symbol(omitSplice1, Decl(arraySpliceParamDescription.ts, 17, 3))
>arrA.splice : Symbol(Array.splice, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --))
>arrA : Symbol(arrA, Decl(arraySpliceParamDescription.ts, 6, 3))
>splice : Symbol(Array.splice, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --))

// testing the splice arrays are empty
isEmptyArr(undefSplice1) // OK and true
>isEmptyArr : Symbol(isEmptyArr, Decl(arraySpliceParamDescription.ts, 0, 0))
>undefSplice1 : Symbol(undefSplice1, Decl(arraySpliceParamDescription.ts, 10, 3))

isEmptyArr(charSplice1) // OK and true
>isEmptyArr : Symbol(isEmptyArr, Decl(arraySpliceParamDescription.ts, 0, 0))
>charSplice1 : Symbol(charSplice1, Decl(arraySpliceParamDescription.ts, 11, 3))

isEmptyArr(naNSplice1) // OK and true
>isEmptyArr : Symbol(isEmptyArr, Decl(arraySpliceParamDescription.ts, 0, 0))
>naNSplice1 : Symbol(naNSplice1, Decl(arraySpliceParamDescription.ts, 12, 3))

isEmptyArr(zeroSplice1) // OK and true
>isEmptyArr : Symbol(isEmptyArr, Decl(arraySpliceParamDescription.ts, 0, 0))
>zeroSplice1 : Symbol(zeroSplice1, Decl(arraySpliceParamDescription.ts, 13, 3))

isEmptyArr(negSplice1) // OK and true
>isEmptyArr : Symbol(isEmptyArr, Decl(arraySpliceParamDescription.ts, 0, 0))
>negSplice1 : Symbol(negSplice1, Decl(arraySpliceParamDescription.ts, 14, 3))

isEmptyArr(omitSplice1) // OK and false. length of removed elements is 5
>isEmptyArr : Symbol(isEmptyArr, Decl(arraySpliceParamDescription.ts, 0, 0))
>omitSplice1 : Symbol(omitSplice1, Decl(arraySpliceParamDescription.ts, 17, 3))

var arrB : string[]
>arrB : Symbol(arrB, Decl(arraySpliceParamDescription.ts, 27, 3))

arrB = ["a", "b", "c", "d", "e", "f", "g"]
>arrB : Symbol(arrB, Decl(arraySpliceParamDescription.ts, 27, 3))

var undefSplice2 = arrB.splice(2, undefined, "h", "i") // expect error and arrB = ["a", "b", "h", "i", "e", "f", "g"]
>undefSplice2 : Symbol(undefSplice2, Decl(arraySpliceParamDescription.ts, 30, 3))
>arrB.splice : Symbol(Array.splice, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --))
>arrB : Symbol(arrB, Decl(arraySpliceParamDescription.ts, 27, 3))
>splice : Symbol(Array.splice, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --))
>undefined : Symbol(undefined)

var omitSplice2 = arrB.splice(2, , "j", "k") // expect error and arrB = ["a", "b", "j", "k", "e", "f", "g"]
>omitSplice2 : Symbol(omitSplice2, Decl(arraySpliceParamDescription.ts, 31, 3))
>arrB.splice : Symbol(Array.splice, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --))
>arrB : Symbol(arrB, Decl(arraySpliceParamDescription.ts, 27, 3))
>splice : Symbol(Array.splice, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --))

var naNSplice2 = arrB.splice(2, NaN, "l", "m") // OK and arrB = ["a", "b", "l", "m", "e", "f", "g"]
>naNSplice2 : Symbol(naNSplice2, Decl(arraySpliceParamDescription.ts, 32, 3))
>arrB.splice : Symbol(Array.splice, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --))
>arrB : Symbol(arrB, Decl(arraySpliceParamDescription.ts, 27, 3))
>splice : Symbol(Array.splice, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --))
>NaN : Symbol(NaN, Decl(lib.es5.d.ts, --, --))

var charSplice2 = arrB.splice(2, "a", "n", "o") // expect error and arrB = ["a", "b", "n", "o", "e", "f", "g"]
>charSplice2 : Symbol(charSplice2, Decl(arraySpliceParamDescription.ts, 33, 3))
>arrB.splice : Symbol(Array.splice, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --))
>arrB : Symbol(arrB, Decl(arraySpliceParamDescription.ts, 27, 3))
>splice : Symbol(Array.splice, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --))

var zeroSplice2 = arrB.splice(2, 0, "p", "q") // OK and arrB = ["a", "b", "p", "q", "e", "f", "g"]
>zeroSplice2 : Symbol(zeroSplice2, Decl(arraySpliceParamDescription.ts, 34, 3))
>arrB.splice : Symbol(Array.splice, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --))
>arrB : Symbol(arrB, Decl(arraySpliceParamDescription.ts, 27, 3))
>splice : Symbol(Array.splice, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --))

var negSplice2 = arrB.splice(2, -2, "r", "s") // OK and arrB = ["a", "b", "r", "s", "e", "f", "g"]
>negSplice2 : Symbol(negSplice2, Decl(arraySpliceParamDescription.ts, 35, 3))
>arrB.splice : Symbol(Array.splice, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --))
>arrB : Symbol(arrB, Decl(arraySpliceParamDescription.ts, 27, 3))
>splice : Symbol(Array.splice, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --))

isEmptyArr(undefSplice2) // OK and true
>isEmptyArr : Symbol(isEmptyArr, Decl(arraySpliceParamDescription.ts, 0, 0))
>undefSplice2 : Symbol(undefSplice2, Decl(arraySpliceParamDescription.ts, 30, 3))

isEmptyArr(omitSplice2) // OK and true
>isEmptyArr : Symbol(isEmptyArr, Decl(arraySpliceParamDescription.ts, 0, 0))
>omitSplice2 : Symbol(omitSplice2, Decl(arraySpliceParamDescription.ts, 31, 3))

isEmptyArr(naNSplice2) // OK and true
>isEmptyArr : Symbol(isEmptyArr, Decl(arraySpliceParamDescription.ts, 0, 0))
>naNSplice2 : Symbol(naNSplice2, Decl(arraySpliceParamDescription.ts, 32, 3))

isEmptyArr(charSplice2) // OK and true
>isEmptyArr : Symbol(isEmptyArr, Decl(arraySpliceParamDescription.ts, 0, 0))
>charSplice2 : Symbol(charSplice2, Decl(arraySpliceParamDescription.ts, 33, 3))

isEmptyArr(zeroSplice2) // OK and true
>isEmptyArr : Symbol(isEmptyArr, Decl(arraySpliceParamDescription.ts, 0, 0))
>zeroSplice2 : Symbol(zeroSplice2, Decl(arraySpliceParamDescription.ts, 34, 3))

isEmptyArr(negSplice2) // OK and true
>isEmptyArr : Symbol(isEmptyArr, Decl(arraySpliceParamDescription.ts, 0, 0))
>negSplice2 : Symbol(negSplice2, Decl(arraySpliceParamDescription.ts, 35, 3))

Loading