Skip to content

Commit 35bdb24

Browse files
committed
Fix the type of copyWithin
Only the first parameter of copyWithin is required, contrary to the old type. This commit fixes that type to allow correct usage of the copyWithin function. See [the usage of copy within](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/copyWithin).
1 parent 905a0b4 commit 35bdb24

7 files changed

+208
-112
lines changed

src/lib/es2015.core.d.ts

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -33,15 +33,23 @@ interface Array<T> {
3333
fill(value: T, start?: number, end?: number): this;
3434

3535
/**
36-
* Returns the this object after copying a section of the array identified by start and end
37-
* to the same array starting at position target
38-
* @param target If target is negative, it is treated as length+target where length is the
39-
* length of the array.
40-
* @param start If start is negative, it is treated as length+start. If end is negative, it
41-
* is treated as length+end.
42-
* @param end If not specified, length of the this object is used as its default value.
43-
*/
44-
copyWithin(target: number, start: number, end?: number): this;
36+
* Return the `this` object after shallow copying part of the array to another location in the same array, without modifying its length.
37+
* @param target Zero-based index at which to copy the sequence to, converted to an integer.
38+
* - Negative index counts back from the end of the array — if `target < 0`, `target + array.length` is used.
39+
* - If `target < -array.length`, `0` is used.
40+
* - If `target >= array.length`, nothing is copied.
41+
* - If `target` is positioned after `start` after normalization, copying only happens until the end of `array.length` (in other words, `copyWithin()` never extends the array).
42+
* @param start Zero-based index at which to start copying elements from, converted to an integer.
43+
* - Negative index counts back from the end of the array — if `start < 0`, `start + array.length` is used.
44+
* - If `start < -array.length` or `start` is omitted, `0` is used.
45+
* - If `start >= array.length`, nothing is copied.
46+
* @param end Zero-based index at which to end copying elements from, converted to an integer. `copyWithin()` copies up to but not including end.
47+
* - Negative index counts back from the end of the array — if `end < 0`, `end + array.length` is used.
48+
* - If `end < -array.length`, `0` is used.
49+
* - If `end >= array.length` or `end` is omitted, `array.length` is used, causing all elements until the end to be copied.
50+
* - If `end` is positioned before or at `start` after normalization, nothing is copied.
51+
*/
52+
copyWithin(target: number, start?: number, end?: number): this;
4553
}
4654

4755
interface ArrayConstructor {

src/lib/es2020.bigint.d.ts

Lines changed: 34 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -142,15 +142,23 @@ interface BigInt64Array {
142142
readonly byteOffset: number;
143143

144144
/**
145-
* Returns the this object after copying a section of the array identified by start and end
146-
* to the same array starting at position target
147-
* @param target If target is negative, it is treated as length+target where length is the
148-
* length of the array.
149-
* @param start If start is negative, it is treated as length+start. If end is negative, it
150-
* is treated as length+end.
151-
* @param end If not specified, length of the this object is used as its default value.
152-
*/
153-
copyWithin(target: number, start: number, end?: number): this;
145+
* Return the `this` object after shallow copying part of the array to another location in the same array, without modifying its length.
146+
* @param target Zero-based index at which to copy the sequence to, converted to an integer.
147+
* - Negative index counts back from the end of the array — if `target < 0`, `target + array.length` is used.
148+
* - If `target < -array.length`, `0` is used.
149+
* - If `target >= array.length`, nothing is copied.
150+
* - If `target` is positioned after `start` after normalization, copying only happens until the end of `array.length` (in other words, `copyWithin()` never extends the array).
151+
* @param start Zero-based index at which to start copying elements from, converted to an integer.
152+
* - Negative index counts back from the end of the array — if `start < 0`, `start + array.length` is used.
153+
* - If `start < -array.length` or `start` is omitted, `0` is used.
154+
* - If `start >= array.length`, nothing is copied.
155+
* @param end Zero-based index at which to end copying elements from, converted to an integer. `copyWithin()` copies up to but not including end.
156+
* - Negative index counts back from the end of the array — if `end < 0`, `end + array.length` is used.
157+
* - If `end < -array.length`, `0` is used.
158+
* - If `end >= array.length` or `end` is omitted, `array.length` is used, causing all elements until the end to be copied.
159+
* - If `end` is positioned before or at `start` after normalization, nothing is copied.
160+
*/
161+
copyWithin(target: number, start?: number, end?: number): this;
154162

155163
/** Yields index, value pairs for every entry in the array. */
156164
entries(): IterableIterator<[number, bigint]>;
@@ -414,15 +422,23 @@ interface BigUint64Array {
414422
readonly byteOffset: number;
415423

416424
/**
417-
* Returns the this object after copying a section of the array identified by start and end
418-
* to the same array starting at position target
419-
* @param target If target is negative, it is treated as length+target where length is the
420-
* length of the array.
421-
* @param start If start is negative, it is treated as length+start. If end is negative, it
422-
* is treated as length+end.
423-
* @param end If not specified, length of the this object is used as its default value.
424-
*/
425-
copyWithin(target: number, start: number, end?: number): this;
425+
* Return the `this` object after shallow copying part of the array to another location in the same array, without modifying its length.
426+
* @param target Zero-based index at which to copy the sequence to, converted to an integer.
427+
* - Negative index counts back from the end of the array — if `target < 0`, `target + array.length` is used.
428+
* - If `target < -array.length`, `0` is used.
429+
* - If `target >= array.length`, nothing is copied.
430+
* - If `target` is positioned after `start` after normalization, copying only happens until the end of `array.length` (in other words, `copyWithin()` never extends the array).
431+
* @param start Zero-based index at which to start copying elements from, converted to an integer.
432+
* - Negative index counts back from the end of the array — if `start < 0`, `start + array.length` is used.
433+
* - If `start < -array.length` or `start` is omitted, `0` is used.
434+
* - If `start >= array.length`, nothing is copied.
435+
* @param end Zero-based index at which to end copying elements from, converted to an integer. `copyWithin()` copies up to but not including end.
436+
* - Negative index counts back from the end of the array — if `end < 0`, `end + array.length` is used.
437+
* - If `end < -array.length`, `0` is used.
438+
* - If `end >= array.length` or `end` is omitted, `array.length` is used, causing all elements until the end to be copied.
439+
* - If `end` is positioned before or at `start` after normalization, nothing is copied.
440+
*/
441+
copyWithin(target: number, start?: number, end?: number): this;
426442

427443
/** Yields index, value pairs for every entry in the array. */
428444
entries(): IterableIterator<[number, bigint]>;

0 commit comments

Comments
 (0)