From 489f49e09a9e3b89381e152a48c6992c77958ed0 Mon Sep 17 00:00:00 2001 From: Christoph Knittel Date: Wed, 28 Oct 2026 15:26:09 +0000 Subject: [PATCH] Type typed-array copyWithin as returning the typed array, and map as keeping the element type Why: `copyWithin` and `copyAllWithin` return the typed array they mutated, but were typed as returning an `array`, so `Array.push` on the result compiled and threw. A typed array's `map` converts each result to its own element type, but `TypedArray.map` let `f` change the type, so a `TypedArray.t` held numbers. Typing modified (TypedArray and per-module externals): Before (rescript): external copyAllWithin: (t<'a>, ~target: int) => array<'a> external map: (t<'a>, 'a => 'b) => t<'b> external mapWithIndex: (t<'a>, ('a, int) => 'b) => t<'b> // Int32Array and the other modules external copyAllWithin: (t, ~target: int) => array After (rescript): external copyAllWithin: (t<'a>, ~target: int) => t<'a> external map: (t<'a>, 'a => 'a) => t<'a> external mapWithIndex: (t<'a>, ('a, int) => 'a) => t<'a> // Int32Array and the other modules external copyAllWithin: (t, ~target: int) => t `copyWithin` changes like `copyAllWithin`, and loses a duplicated `@send`. Breaking: `TypedArray.map` and `mapWithIndex` no longer change the element type; to get values of another type, build an `array` from the elements. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01Kbf3gGkPma9LAZimuQjnrP Signed-off-by: Christoph Knittel --- changes/typed-array-copy-within.fix.md | 1 + .../typed-array-map-element-type.breaking.md | 1 + .../@rescript/runtime/Stdlib_TypedArray.res | 26 ++--- .../expected/CompletionTypedArrays.res.txt | 110 +++++++++--------- .../TypedArrayMapElementType.res.expected | 12 ++ .../fixtures/TypedArrayMapElementType.res | 2 + .../src/stdlib/Stdlib_TypedArrayTests.mjs | 73 ++++++++++++ .../src/stdlib/Stdlib_TypedArrayTests.res | 33 ++++++ 8 files changed, 190 insertions(+), 68 deletions(-) create mode 100644 changes/typed-array-copy-within.fix.md create mode 100644 changes/typed-array-map-element-type.breaking.md create mode 100644 tests/build_tests/super_errors/expected/TypedArrayMapElementType.res.expected create mode 100644 tests/build_tests/super_errors/fixtures/TypedArrayMapElementType.res diff --git a/changes/typed-array-copy-within.fix.md b/changes/typed-array-copy-within.fix.md new file mode 100644 index 0000000000..5c055f9b38 --- /dev/null +++ b/changes/typed-array-copy-within.fix.md @@ -0,0 +1 @@ +- Type `copyWithin` and `copyAllWithin` of typed arrays as returning the typed array instead of an `array`. diff --git a/changes/typed-array-map-element-type.breaking.md b/changes/typed-array-map-element-type.breaking.md new file mode 100644 index 0000000000..00f6cd234f --- /dev/null +++ b/changes/typed-array-map-element-type.breaking.md @@ -0,0 +1 @@ +- `TypedArray.map` and `TypedArray.mapWithIndex` now keep the element type, because a typed array converts the results of `map` to its own element type. diff --git a/packages/@rescript/runtime/Stdlib_TypedArray.res b/packages/@rescript/runtime/Stdlib_TypedArray.res index fb0e71bcdc..82ef4c4f1c 100644 --- a/packages/@rescript/runtime/Stdlib_TypedArray.res +++ b/packages/@rescript/runtime/Stdlib_TypedArray.res @@ -111,7 +111,7 @@ TypedArray.length(view) == 3 external length: t<'a> => int = "length" /** -`copyAllWithin(typedArray, ~target)` copies values starting at index `0` over the positions beginning at `target`. +`copyAllWithin(typedArray, ~target)` copies values starting at index `0` over the positions beginning at `target`, and returns `typedArray`. Beware this will *mutate* the typed array. @@ -125,9 +125,9 @@ let _ = TypedArray.copyAllWithin(view, ~target=1) TypedArray.toString(view) == "10,10,20" ``` */ -@send external copyAllWithin: (t<'a>, ~target: int) => array<'a> = "copyWithin" +@send external copyAllWithin: (t<'a>, ~target: int) => t<'a> = "copyWithin" /** -`copyWithin(typedArray, ~target, ~start, ~end)` copies the section `[start, end)` onto the range beginning at `target`. +`copyWithin(typedArray, ~target, ~start, ~end)` copies the section `[start, end)` onto the range beginning at `target`, and returns `typedArray`. Beware this will *mutate* the typed array. @@ -141,8 +141,8 @@ let _ = TypedArray.copyWithin(view, ~target=1, ~start=2, ~end=4) TypedArray.toString(view) == "1,3,4,4" ``` */ -@send @send -external copyWithin: (t<'a>, ~target: int, ~start: int, ~end: int=?) => array<'a> = "copyWithin" +@send +external copyWithin: (t<'a>, ~target: int, ~start: int, ~end: int=?) => t<'a> = "copyWithin" /** `fillAll(typedArray, value)` fills every element with `value`. @@ -409,15 +409,15 @@ See [`TypedArray.prototype.forEach`](https://developer.mozilla.org/en-US/docs/We @send external forEachWithIndex: (t<'a>, ('a, int) => unit) => unit = "forEach" /** -`map(typedArray, f)` returns a new typed array whose elements are produced by applying `f` to each element. +`map(typedArray, f)` returns a new typed array of the same kind whose elements are produced by applying `f` to each element. See [`TypedArray.prototype.map`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray/map) on MDN. */ -@send external map: (t<'a>, 'a => 'b) => t<'b> = "map" +@send external map: (t<'a>, 'a => 'a) => t<'a> = "map" /** `mapWithIndex(typedArray, f)` behaves like `map`, but `f` also receives the index. */ -@send external mapWithIndex: (t<'a>, ('a, int) => 'b) => t<'b> = "map" +@send external mapWithIndex: (t<'a>, ('a, int) => 'a) => t<'a> = "map" /** `reduce(typedArray, reducer, initial)` combines the elements from left to right using `reducer`. @@ -582,7 +582,7 @@ module Impl = ( external length: T.t => int = "length" /** - `copyAllWithin(typedArray, ~target)` copies values starting at index `0` over the positions beginning at `target`. + `copyAllWithin(typedArray, ~target)` copies values starting at index `0` over the positions beginning at `target`, and returns `typedArray`. Beware this will *mutate* the typed array. @@ -597,10 +597,10 @@ module Impl = ( ``` */ @send - external copyAllWithin: (T.t, ~target: int) => array = "copyWithin" + external copyAllWithin: (T.t, ~target: int) => T.t = "copyWithin" /** - `copyWithin(typedArray, ~target, ~start, ~end)` copies the section `[start, end)` onto the range beginning at `target`. + `copyWithin(typedArray, ~target, ~start, ~end)` copies the section `[start, end)` onto the range beginning at `target`, and returns `typedArray`. Beware this will *mutate* the typed array. @@ -615,7 +615,7 @@ module Impl = ( ``` */ @send - external copyWithin: (T.t, ~target: int, ~start: int, ~end: int=?) => array = "copyWithin" + external copyWithin: (T.t, ~target: int, ~start: int, ~end: int=?) => T.t = "copyWithin" /** `fillAll(typedArray, value)` fills every element with `value`. @@ -926,7 +926,7 @@ module Impl = ( external forEachWithIndex: (T.t, (T.elt, int) => unit) => unit = "forEach" /** - `map(typedArray, f)` returns a new typed array whose elements are produced by applying `f` to each element. + `map(typedArray, f)` returns a new typed array of the same kind whose elements are produced by applying `f` to each element. See [`TypedArray.prototype.map`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray/map) on MDN. */ diff --git a/tests/analysis_tests/tests/src/expected/CompletionTypedArrays.res.txt b/tests/analysis_tests/tests/src/expected/CompletionTypedArrays.res.txt index fada75b087..7d6dc0a7f5 100644 --- a/tests/analysis_tests/tests/src/expected/CompletionTypedArrays.res.txt +++ b/tests/analysis_tests/tests/src/expected/CompletionTypedArrays.res.txt @@ -720,7 +720,7 @@ Path "detail": "(t, bigint => bigint) => t", "documentation": { "kind": "markdown", - "value": "\n `map(typedArray, f)` returns a new typed array whose elements are produced by applying `f` to each element.\n\n See [`TypedArray.prototype.map`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray/map) on MDN.\n " + "value": "\n `map(typedArray, f)` returns a new typed array of the same kind whose elements are produced by applying `f` to each element.\n\n See [`TypedArray.prototype.map`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray/map) on MDN.\n " }, "insertText": "->BigInt64Array.map", "kind": 12, @@ -759,10 +759,10 @@ Path } } ], - "detail": "(t, ~target: int) => array", + "detail": "(t, ~target: int) => t", "documentation": { "kind": "markdown", - "value": "\n `copyAllWithin(typedArray, ~target)` copies values starting at index `0` over the positions beginning at `target`.\n\n Beware this will *mutate* the typed array.\n\n See [`TypedArray.prototype.copyWithin`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray/copyWithin) on MDN.\n\n ## Examples\n\n ```rescript\n let view = Int32Array.fromArray([10, 20, 30])\n let _ = Int32Array.copyAllWithin(view, ~target=1)\n Int32Array.toString(view) == \"10,10,20\"\n ```\n " + "value": "\n `copyAllWithin(typedArray, ~target)` copies values starting at index `0` over the positions beginning at `target`, and returns `typedArray`.\n\n Beware this will *mutate* the typed array.\n\n See [`TypedArray.prototype.copyWithin`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray/copyWithin) on MDN.\n\n ## Examples\n\n ```rescript\n let view = Int32Array.fromArray([10, 20, 30])\n let _ = Int32Array.copyAllWithin(view, ~target=1)\n Int32Array.toString(view) == \"10,10,20\"\n ```\n " }, "insertText": "->BigInt64Array.copyAllWithin", "kind": 12, @@ -885,10 +885,10 @@ Path } } ], - "detail": "(t, ~target: int, ~start: int, ~end: int=?) => array", + "detail": "(t, ~target: int, ~start: int, ~end: int=?) => t", "documentation": { "kind": "markdown", - "value": "\n `copyWithin(typedArray, ~target, ~start, ~end)` copies the section `[start, end)` onto the range beginning at `target`.\n\n Beware this will *mutate* the typed array.\n\n See [`TypedArray.prototype.copyWithin`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray/copyWithin) on MDN.\n\n ## Examples\n\n ```rescript\n let view = Int32Array.fromArray([1, 2, 3, 4])\n let _ = Int32Array.copyWithin(view, ~target=1, ~start=2, ~end=4)\n Int32Array.toString(view) == \"1,3,4,4\"\n ```\n " + "value": "\n `copyWithin(typedArray, ~target, ~start, ~end)` copies the section `[start, end)` onto the range beginning at `target`, and returns `typedArray`.\n\n Beware this will *mutate* the typed array.\n\n See [`TypedArray.prototype.copyWithin`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray/copyWithin) on MDN.\n\n ## Examples\n\n ```rescript\n let view = Int32Array.fromArray([1, 2, 3, 4])\n let _ = Int32Array.copyWithin(view, ~target=1, ~start=2, ~end=4)\n Int32Array.toString(view) == \"1,3,4,4\"\n ```\n " }, "insertText": "->BigInt64Array.copyWithin", "kind": 12, @@ -1809,7 +1809,7 @@ Path "detail": "(t, bigint => bigint) => t", "documentation": { "kind": "markdown", - "value": "\n `map(typedArray, f)` returns a new typed array whose elements are produced by applying `f` to each element.\n\n See [`TypedArray.prototype.map`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray/map) on MDN.\n " + "value": "\n `map(typedArray, f)` returns a new typed array of the same kind whose elements are produced by applying `f` to each element.\n\n See [`TypedArray.prototype.map`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray/map) on MDN.\n " }, "insertText": "->BigUint64Array.map", "kind": 12, @@ -1848,10 +1848,10 @@ Path } } ], - "detail": "(t, ~target: int) => array", + "detail": "(t, ~target: int) => t", "documentation": { "kind": "markdown", - "value": "\n `copyAllWithin(typedArray, ~target)` copies values starting at index `0` over the positions beginning at `target`.\n\n Beware this will *mutate* the typed array.\n\n See [`TypedArray.prototype.copyWithin`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray/copyWithin) on MDN.\n\n ## Examples\n\n ```rescript\n let view = Int32Array.fromArray([10, 20, 30])\n let _ = Int32Array.copyAllWithin(view, ~target=1)\n Int32Array.toString(view) == \"10,10,20\"\n ```\n " + "value": "\n `copyAllWithin(typedArray, ~target)` copies values starting at index `0` over the positions beginning at `target`, and returns `typedArray`.\n\n Beware this will *mutate* the typed array.\n\n See [`TypedArray.prototype.copyWithin`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray/copyWithin) on MDN.\n\n ## Examples\n\n ```rescript\n let view = Int32Array.fromArray([10, 20, 30])\n let _ = Int32Array.copyAllWithin(view, ~target=1)\n Int32Array.toString(view) == \"10,10,20\"\n ```\n " }, "insertText": "->BigUint64Array.copyAllWithin", "kind": 12, @@ -1974,10 +1974,10 @@ Path } } ], - "detail": "(t, ~target: int, ~start: int, ~end: int=?) => array", + "detail": "(t, ~target: int, ~start: int, ~end: int=?) => t", "documentation": { "kind": "markdown", - "value": "\n `copyWithin(typedArray, ~target, ~start, ~end)` copies the section `[start, end)` onto the range beginning at `target`.\n\n Beware this will *mutate* the typed array.\n\n See [`TypedArray.prototype.copyWithin`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray/copyWithin) on MDN.\n\n ## Examples\n\n ```rescript\n let view = Int32Array.fromArray([1, 2, 3, 4])\n let _ = Int32Array.copyWithin(view, ~target=1, ~start=2, ~end=4)\n Int32Array.toString(view) == \"1,3,4,4\"\n ```\n " + "value": "\n `copyWithin(typedArray, ~target, ~start, ~end)` copies the section `[start, end)` onto the range beginning at `target`, and returns `typedArray`.\n\n Beware this will *mutate* the typed array.\n\n See [`TypedArray.prototype.copyWithin`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray/copyWithin) on MDN.\n\n ## Examples\n\n ```rescript\n let view = Int32Array.fromArray([1, 2, 3, 4])\n let _ = Int32Array.copyWithin(view, ~target=1, ~start=2, ~end=4)\n Int32Array.toString(view) == \"1,3,4,4\"\n ```\n " }, "insertText": "->BigUint64Array.copyWithin", "kind": 12, @@ -2898,7 +2898,7 @@ Path "detail": "(t, float => float) => t", "documentation": { "kind": "markdown", - "value": "\n `map(typedArray, f)` returns a new typed array whose elements are produced by applying `f` to each element.\n\n See [`TypedArray.prototype.map`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray/map) on MDN.\n " + "value": "\n `map(typedArray, f)` returns a new typed array of the same kind whose elements are produced by applying `f` to each element.\n\n See [`TypedArray.prototype.map`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray/map) on MDN.\n " }, "insertText": "->Float32Array.map", "kind": 12, @@ -2937,10 +2937,10 @@ Path } } ], - "detail": "(t, ~target: int) => array", + "detail": "(t, ~target: int) => t", "documentation": { "kind": "markdown", - "value": "\n `copyAllWithin(typedArray, ~target)` copies values starting at index `0` over the positions beginning at `target`.\n\n Beware this will *mutate* the typed array.\n\n See [`TypedArray.prototype.copyWithin`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray/copyWithin) on MDN.\n\n ## Examples\n\n ```rescript\n let view = Int32Array.fromArray([10, 20, 30])\n let _ = Int32Array.copyAllWithin(view, ~target=1)\n Int32Array.toString(view) == \"10,10,20\"\n ```\n " + "value": "\n `copyAllWithin(typedArray, ~target)` copies values starting at index `0` over the positions beginning at `target`, and returns `typedArray`.\n\n Beware this will *mutate* the typed array.\n\n See [`TypedArray.prototype.copyWithin`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray/copyWithin) on MDN.\n\n ## Examples\n\n ```rescript\n let view = Int32Array.fromArray([10, 20, 30])\n let _ = Int32Array.copyAllWithin(view, ~target=1)\n Int32Array.toString(view) == \"10,10,20\"\n ```\n " }, "insertText": "->Float32Array.copyAllWithin", "kind": 12, @@ -3063,10 +3063,10 @@ Path } } ], - "detail": "(t, ~target: int, ~start: int, ~end: int=?) => array", + "detail": "(t, ~target: int, ~start: int, ~end: int=?) => t", "documentation": { "kind": "markdown", - "value": "\n `copyWithin(typedArray, ~target, ~start, ~end)` copies the section `[start, end)` onto the range beginning at `target`.\n\n Beware this will *mutate* the typed array.\n\n See [`TypedArray.prototype.copyWithin`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray/copyWithin) on MDN.\n\n ## Examples\n\n ```rescript\n let view = Int32Array.fromArray([1, 2, 3, 4])\n let _ = Int32Array.copyWithin(view, ~target=1, ~start=2, ~end=4)\n Int32Array.toString(view) == \"1,3,4,4\"\n ```\n " + "value": "\n `copyWithin(typedArray, ~target, ~start, ~end)` copies the section `[start, end)` onto the range beginning at `target`, and returns `typedArray`.\n\n Beware this will *mutate* the typed array.\n\n See [`TypedArray.prototype.copyWithin`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray/copyWithin) on MDN.\n\n ## Examples\n\n ```rescript\n let view = Int32Array.fromArray([1, 2, 3, 4])\n let _ = Int32Array.copyWithin(view, ~target=1, ~start=2, ~end=4)\n Int32Array.toString(view) == \"1,3,4,4\"\n ```\n " }, "insertText": "->Float32Array.copyWithin", "kind": 12, @@ -3987,7 +3987,7 @@ Path "detail": "(t, float => float) => t", "documentation": { "kind": "markdown", - "value": "\n `map(typedArray, f)` returns a new typed array whose elements are produced by applying `f` to each element.\n\n See [`TypedArray.prototype.map`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray/map) on MDN.\n " + "value": "\n `map(typedArray, f)` returns a new typed array of the same kind whose elements are produced by applying `f` to each element.\n\n See [`TypedArray.prototype.map`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray/map) on MDN.\n " }, "insertText": "->Float64Array.map", "kind": 12, @@ -4026,10 +4026,10 @@ Path } } ], - "detail": "(t, ~target: int) => array", + "detail": "(t, ~target: int) => t", "documentation": { "kind": "markdown", - "value": "\n `copyAllWithin(typedArray, ~target)` copies values starting at index `0` over the positions beginning at `target`.\n\n Beware this will *mutate* the typed array.\n\n See [`TypedArray.prototype.copyWithin`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray/copyWithin) on MDN.\n\n ## Examples\n\n ```rescript\n let view = Int32Array.fromArray([10, 20, 30])\n let _ = Int32Array.copyAllWithin(view, ~target=1)\n Int32Array.toString(view) == \"10,10,20\"\n ```\n " + "value": "\n `copyAllWithin(typedArray, ~target)` copies values starting at index `0` over the positions beginning at `target`, and returns `typedArray`.\n\n Beware this will *mutate* the typed array.\n\n See [`TypedArray.prototype.copyWithin`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray/copyWithin) on MDN.\n\n ## Examples\n\n ```rescript\n let view = Int32Array.fromArray([10, 20, 30])\n let _ = Int32Array.copyAllWithin(view, ~target=1)\n Int32Array.toString(view) == \"10,10,20\"\n ```\n " }, "insertText": "->Float64Array.copyAllWithin", "kind": 12, @@ -4152,10 +4152,10 @@ Path } } ], - "detail": "(t, ~target: int, ~start: int, ~end: int=?) => array", + "detail": "(t, ~target: int, ~start: int, ~end: int=?) => t", "documentation": { "kind": "markdown", - "value": "\n `copyWithin(typedArray, ~target, ~start, ~end)` copies the section `[start, end)` onto the range beginning at `target`.\n\n Beware this will *mutate* the typed array.\n\n See [`TypedArray.prototype.copyWithin`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray/copyWithin) on MDN.\n\n ## Examples\n\n ```rescript\n let view = Int32Array.fromArray([1, 2, 3, 4])\n let _ = Int32Array.copyWithin(view, ~target=1, ~start=2, ~end=4)\n Int32Array.toString(view) == \"1,3,4,4\"\n ```\n " + "value": "\n `copyWithin(typedArray, ~target, ~start, ~end)` copies the section `[start, end)` onto the range beginning at `target`, and returns `typedArray`.\n\n Beware this will *mutate* the typed array.\n\n See [`TypedArray.prototype.copyWithin`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray/copyWithin) on MDN.\n\n ## Examples\n\n ```rescript\n let view = Int32Array.fromArray([1, 2, 3, 4])\n let _ = Int32Array.copyWithin(view, ~target=1, ~start=2, ~end=4)\n Int32Array.toString(view) == \"1,3,4,4\"\n ```\n " }, "insertText": "->Float64Array.copyWithin", "kind": 12, @@ -5076,7 +5076,7 @@ Path "detail": "(t, int => int) => t", "documentation": { "kind": "markdown", - "value": "\n `map(typedArray, f)` returns a new typed array whose elements are produced by applying `f` to each element.\n\n See [`TypedArray.prototype.map`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray/map) on MDN.\n " + "value": "\n `map(typedArray, f)` returns a new typed array of the same kind whose elements are produced by applying `f` to each element.\n\n See [`TypedArray.prototype.map`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray/map) on MDN.\n " }, "insertText": "->Int16Array.map", "kind": 12, @@ -5115,10 +5115,10 @@ Path } } ], - "detail": "(t, ~target: int) => array", + "detail": "(t, ~target: int) => t", "documentation": { "kind": "markdown", - "value": "\n `copyAllWithin(typedArray, ~target)` copies values starting at index `0` over the positions beginning at `target`.\n\n Beware this will *mutate* the typed array.\n\n See [`TypedArray.prototype.copyWithin`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray/copyWithin) on MDN.\n\n ## Examples\n\n ```rescript\n let view = Int32Array.fromArray([10, 20, 30])\n let _ = Int32Array.copyAllWithin(view, ~target=1)\n Int32Array.toString(view) == \"10,10,20\"\n ```\n " + "value": "\n `copyAllWithin(typedArray, ~target)` copies values starting at index `0` over the positions beginning at `target`, and returns `typedArray`.\n\n Beware this will *mutate* the typed array.\n\n See [`TypedArray.prototype.copyWithin`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray/copyWithin) on MDN.\n\n ## Examples\n\n ```rescript\n let view = Int32Array.fromArray([10, 20, 30])\n let _ = Int32Array.copyAllWithin(view, ~target=1)\n Int32Array.toString(view) == \"10,10,20\"\n ```\n " }, "insertText": "->Int16Array.copyAllWithin", "kind": 12, @@ -5241,10 +5241,10 @@ Path } } ], - "detail": "(t, ~target: int, ~start: int, ~end: int=?) => array", + "detail": "(t, ~target: int, ~start: int, ~end: int=?) => t", "documentation": { "kind": "markdown", - "value": "\n `copyWithin(typedArray, ~target, ~start, ~end)` copies the section `[start, end)` onto the range beginning at `target`.\n\n Beware this will *mutate* the typed array.\n\n See [`TypedArray.prototype.copyWithin`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray/copyWithin) on MDN.\n\n ## Examples\n\n ```rescript\n let view = Int32Array.fromArray([1, 2, 3, 4])\n let _ = Int32Array.copyWithin(view, ~target=1, ~start=2, ~end=4)\n Int32Array.toString(view) == \"1,3,4,4\"\n ```\n " + "value": "\n `copyWithin(typedArray, ~target, ~start, ~end)` copies the section `[start, end)` onto the range beginning at `target`, and returns `typedArray`.\n\n Beware this will *mutate* the typed array.\n\n See [`TypedArray.prototype.copyWithin`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray/copyWithin) on MDN.\n\n ## Examples\n\n ```rescript\n let view = Int32Array.fromArray([1, 2, 3, 4])\n let _ = Int32Array.copyWithin(view, ~target=1, ~start=2, ~end=4)\n Int32Array.toString(view) == \"1,3,4,4\"\n ```\n " }, "insertText": "->Int16Array.copyWithin", "kind": 12, @@ -6165,7 +6165,7 @@ Path "detail": "(t, int => int) => t", "documentation": { "kind": "markdown", - "value": "\n `map(typedArray, f)` returns a new typed array whose elements are produced by applying `f` to each element.\n\n See [`TypedArray.prototype.map`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray/map) on MDN.\n " + "value": "\n `map(typedArray, f)` returns a new typed array of the same kind whose elements are produced by applying `f` to each element.\n\n See [`TypedArray.prototype.map`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray/map) on MDN.\n " }, "insertText": "->Int32Array.map", "kind": 12, @@ -6204,10 +6204,10 @@ Path } } ], - "detail": "(t, ~target: int) => array", + "detail": "(t, ~target: int) => t", "documentation": { "kind": "markdown", - "value": "\n `copyAllWithin(typedArray, ~target)` copies values starting at index `0` over the positions beginning at `target`.\n\n Beware this will *mutate* the typed array.\n\n See [`TypedArray.prototype.copyWithin`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray/copyWithin) on MDN.\n\n ## Examples\n\n ```rescript\n let view = Int32Array.fromArray([10, 20, 30])\n let _ = Int32Array.copyAllWithin(view, ~target=1)\n Int32Array.toString(view) == \"10,10,20\"\n ```\n " + "value": "\n `copyAllWithin(typedArray, ~target)` copies values starting at index `0` over the positions beginning at `target`, and returns `typedArray`.\n\n Beware this will *mutate* the typed array.\n\n See [`TypedArray.prototype.copyWithin`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray/copyWithin) on MDN.\n\n ## Examples\n\n ```rescript\n let view = Int32Array.fromArray([10, 20, 30])\n let _ = Int32Array.copyAllWithin(view, ~target=1)\n Int32Array.toString(view) == \"10,10,20\"\n ```\n " }, "insertText": "->Int32Array.copyAllWithin", "kind": 12, @@ -6330,10 +6330,10 @@ Path } } ], - "detail": "(t, ~target: int, ~start: int, ~end: int=?) => array", + "detail": "(t, ~target: int, ~start: int, ~end: int=?) => t", "documentation": { "kind": "markdown", - "value": "\n `copyWithin(typedArray, ~target, ~start, ~end)` copies the section `[start, end)` onto the range beginning at `target`.\n\n Beware this will *mutate* the typed array.\n\n See [`TypedArray.prototype.copyWithin`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray/copyWithin) on MDN.\n\n ## Examples\n\n ```rescript\n let view = Int32Array.fromArray([1, 2, 3, 4])\n let _ = Int32Array.copyWithin(view, ~target=1, ~start=2, ~end=4)\n Int32Array.toString(view) == \"1,3,4,4\"\n ```\n " + "value": "\n `copyWithin(typedArray, ~target, ~start, ~end)` copies the section `[start, end)` onto the range beginning at `target`, and returns `typedArray`.\n\n Beware this will *mutate* the typed array.\n\n See [`TypedArray.prototype.copyWithin`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray/copyWithin) on MDN.\n\n ## Examples\n\n ```rescript\n let view = Int32Array.fromArray([1, 2, 3, 4])\n let _ = Int32Array.copyWithin(view, ~target=1, ~start=2, ~end=4)\n Int32Array.toString(view) == \"1,3,4,4\"\n ```\n " }, "insertText": "->Int32Array.copyWithin", "kind": 12, @@ -7254,7 +7254,7 @@ Path "detail": "(t, int => int) => t", "documentation": { "kind": "markdown", - "value": "\n `map(typedArray, f)` returns a new typed array whose elements are produced by applying `f` to each element.\n\n See [`TypedArray.prototype.map`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray/map) on MDN.\n " + "value": "\n `map(typedArray, f)` returns a new typed array of the same kind whose elements are produced by applying `f` to each element.\n\n See [`TypedArray.prototype.map`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray/map) on MDN.\n " }, "insertText": "->Int8Array.map", "kind": 12, @@ -7293,10 +7293,10 @@ Path } } ], - "detail": "(t, ~target: int) => array", + "detail": "(t, ~target: int) => t", "documentation": { "kind": "markdown", - "value": "\n `copyAllWithin(typedArray, ~target)` copies values starting at index `0` over the positions beginning at `target`.\n\n Beware this will *mutate* the typed array.\n\n See [`TypedArray.prototype.copyWithin`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray/copyWithin) on MDN.\n\n ## Examples\n\n ```rescript\n let view = Int32Array.fromArray([10, 20, 30])\n let _ = Int32Array.copyAllWithin(view, ~target=1)\n Int32Array.toString(view) == \"10,10,20\"\n ```\n " + "value": "\n `copyAllWithin(typedArray, ~target)` copies values starting at index `0` over the positions beginning at `target`, and returns `typedArray`.\n\n Beware this will *mutate* the typed array.\n\n See [`TypedArray.prototype.copyWithin`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray/copyWithin) on MDN.\n\n ## Examples\n\n ```rescript\n let view = Int32Array.fromArray([10, 20, 30])\n let _ = Int32Array.copyAllWithin(view, ~target=1)\n Int32Array.toString(view) == \"10,10,20\"\n ```\n " }, "insertText": "->Int8Array.copyAllWithin", "kind": 12, @@ -7419,10 +7419,10 @@ Path } } ], - "detail": "(t, ~target: int, ~start: int, ~end: int=?) => array", + "detail": "(t, ~target: int, ~start: int, ~end: int=?) => t", "documentation": { "kind": "markdown", - "value": "\n `copyWithin(typedArray, ~target, ~start, ~end)` copies the section `[start, end)` onto the range beginning at `target`.\n\n Beware this will *mutate* the typed array.\n\n See [`TypedArray.prototype.copyWithin`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray/copyWithin) on MDN.\n\n ## Examples\n\n ```rescript\n let view = Int32Array.fromArray([1, 2, 3, 4])\n let _ = Int32Array.copyWithin(view, ~target=1, ~start=2, ~end=4)\n Int32Array.toString(view) == \"1,3,4,4\"\n ```\n " + "value": "\n `copyWithin(typedArray, ~target, ~start, ~end)` copies the section `[start, end)` onto the range beginning at `target`, and returns `typedArray`.\n\n Beware this will *mutate* the typed array.\n\n See [`TypedArray.prototype.copyWithin`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray/copyWithin) on MDN.\n\n ## Examples\n\n ```rescript\n let view = Int32Array.fromArray([1, 2, 3, 4])\n let _ = Int32Array.copyWithin(view, ~target=1, ~start=2, ~end=4)\n Int32Array.toString(view) == \"1,3,4,4\"\n ```\n " }, "insertText": "->Int8Array.copyWithin", "kind": 12, @@ -8343,7 +8343,7 @@ Path "detail": "(t, int => int) => t", "documentation": { "kind": "markdown", - "value": "\n `map(typedArray, f)` returns a new typed array whose elements are produced by applying `f` to each element.\n\n See [`TypedArray.prototype.map`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray/map) on MDN.\n " + "value": "\n `map(typedArray, f)` returns a new typed array of the same kind whose elements are produced by applying `f` to each element.\n\n See [`TypedArray.prototype.map`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray/map) on MDN.\n " }, "insertText": "->Uint16Array.map", "kind": 12, @@ -8382,10 +8382,10 @@ Path } } ], - "detail": "(t, ~target: int) => array", + "detail": "(t, ~target: int) => t", "documentation": { "kind": "markdown", - "value": "\n `copyAllWithin(typedArray, ~target)` copies values starting at index `0` over the positions beginning at `target`.\n\n Beware this will *mutate* the typed array.\n\n See [`TypedArray.prototype.copyWithin`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray/copyWithin) on MDN.\n\n ## Examples\n\n ```rescript\n let view = Int32Array.fromArray([10, 20, 30])\n let _ = Int32Array.copyAllWithin(view, ~target=1)\n Int32Array.toString(view) == \"10,10,20\"\n ```\n " + "value": "\n `copyAllWithin(typedArray, ~target)` copies values starting at index `0` over the positions beginning at `target`, and returns `typedArray`.\n\n Beware this will *mutate* the typed array.\n\n See [`TypedArray.prototype.copyWithin`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray/copyWithin) on MDN.\n\n ## Examples\n\n ```rescript\n let view = Int32Array.fromArray([10, 20, 30])\n let _ = Int32Array.copyAllWithin(view, ~target=1)\n Int32Array.toString(view) == \"10,10,20\"\n ```\n " }, "insertText": "->Uint16Array.copyAllWithin", "kind": 12, @@ -8508,10 +8508,10 @@ Path } } ], - "detail": "(t, ~target: int, ~start: int, ~end: int=?) => array", + "detail": "(t, ~target: int, ~start: int, ~end: int=?) => t", "documentation": { "kind": "markdown", - "value": "\n `copyWithin(typedArray, ~target, ~start, ~end)` copies the section `[start, end)` onto the range beginning at `target`.\n\n Beware this will *mutate* the typed array.\n\n See [`TypedArray.prototype.copyWithin`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray/copyWithin) on MDN.\n\n ## Examples\n\n ```rescript\n let view = Int32Array.fromArray([1, 2, 3, 4])\n let _ = Int32Array.copyWithin(view, ~target=1, ~start=2, ~end=4)\n Int32Array.toString(view) == \"1,3,4,4\"\n ```\n " + "value": "\n `copyWithin(typedArray, ~target, ~start, ~end)` copies the section `[start, end)` onto the range beginning at `target`, and returns `typedArray`.\n\n Beware this will *mutate* the typed array.\n\n See [`TypedArray.prototype.copyWithin`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray/copyWithin) on MDN.\n\n ## Examples\n\n ```rescript\n let view = Int32Array.fromArray([1, 2, 3, 4])\n let _ = Int32Array.copyWithin(view, ~target=1, ~start=2, ~end=4)\n Int32Array.toString(view) == \"1,3,4,4\"\n ```\n " }, "insertText": "->Uint16Array.copyWithin", "kind": 12, @@ -9432,7 +9432,7 @@ Path "detail": "(t, int => int) => t", "documentation": { "kind": "markdown", - "value": "\n `map(typedArray, f)` returns a new typed array whose elements are produced by applying `f` to each element.\n\n See [`TypedArray.prototype.map`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray/map) on MDN.\n " + "value": "\n `map(typedArray, f)` returns a new typed array of the same kind whose elements are produced by applying `f` to each element.\n\n See [`TypedArray.prototype.map`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray/map) on MDN.\n " }, "insertText": "->Uint32Array.map", "kind": 12, @@ -9471,10 +9471,10 @@ Path } } ], - "detail": "(t, ~target: int) => array", + "detail": "(t, ~target: int) => t", "documentation": { "kind": "markdown", - "value": "\n `copyAllWithin(typedArray, ~target)` copies values starting at index `0` over the positions beginning at `target`.\n\n Beware this will *mutate* the typed array.\n\n See [`TypedArray.prototype.copyWithin`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray/copyWithin) on MDN.\n\n ## Examples\n\n ```rescript\n let view = Int32Array.fromArray([10, 20, 30])\n let _ = Int32Array.copyAllWithin(view, ~target=1)\n Int32Array.toString(view) == \"10,10,20\"\n ```\n " + "value": "\n `copyAllWithin(typedArray, ~target)` copies values starting at index `0` over the positions beginning at `target`, and returns `typedArray`.\n\n Beware this will *mutate* the typed array.\n\n See [`TypedArray.prototype.copyWithin`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray/copyWithin) on MDN.\n\n ## Examples\n\n ```rescript\n let view = Int32Array.fromArray([10, 20, 30])\n let _ = Int32Array.copyAllWithin(view, ~target=1)\n Int32Array.toString(view) == \"10,10,20\"\n ```\n " }, "insertText": "->Uint32Array.copyAllWithin", "kind": 12, @@ -9597,10 +9597,10 @@ Path } } ], - "detail": "(t, ~target: int, ~start: int, ~end: int=?) => array", + "detail": "(t, ~target: int, ~start: int, ~end: int=?) => t", "documentation": { "kind": "markdown", - "value": "\n `copyWithin(typedArray, ~target, ~start, ~end)` copies the section `[start, end)` onto the range beginning at `target`.\n\n Beware this will *mutate* the typed array.\n\n See [`TypedArray.prototype.copyWithin`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray/copyWithin) on MDN.\n\n ## Examples\n\n ```rescript\n let view = Int32Array.fromArray([1, 2, 3, 4])\n let _ = Int32Array.copyWithin(view, ~target=1, ~start=2, ~end=4)\n Int32Array.toString(view) == \"1,3,4,4\"\n ```\n " + "value": "\n `copyWithin(typedArray, ~target, ~start, ~end)` copies the section `[start, end)` onto the range beginning at `target`, and returns `typedArray`.\n\n Beware this will *mutate* the typed array.\n\n See [`TypedArray.prototype.copyWithin`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray/copyWithin) on MDN.\n\n ## Examples\n\n ```rescript\n let view = Int32Array.fromArray([1, 2, 3, 4])\n let _ = Int32Array.copyWithin(view, ~target=1, ~start=2, ~end=4)\n Int32Array.toString(view) == \"1,3,4,4\"\n ```\n " }, "insertText": "->Uint32Array.copyWithin", "kind": 12, @@ -10521,7 +10521,7 @@ Path "detail": "(t, int => int) => t", "documentation": { "kind": "markdown", - "value": "\n `map(typedArray, f)` returns a new typed array whose elements are produced by applying `f` to each element.\n\n See [`TypedArray.prototype.map`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray/map) on MDN.\n " + "value": "\n `map(typedArray, f)` returns a new typed array of the same kind whose elements are produced by applying `f` to each element.\n\n See [`TypedArray.prototype.map`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray/map) on MDN.\n " }, "insertText": "->Uint8Array.map", "kind": 12, @@ -10560,10 +10560,10 @@ Path } } ], - "detail": "(t, ~target: int) => array", + "detail": "(t, ~target: int) => t", "documentation": { "kind": "markdown", - "value": "\n `copyAllWithin(typedArray, ~target)` copies values starting at index `0` over the positions beginning at `target`.\n\n Beware this will *mutate* the typed array.\n\n See [`TypedArray.prototype.copyWithin`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray/copyWithin) on MDN.\n\n ## Examples\n\n ```rescript\n let view = Int32Array.fromArray([10, 20, 30])\n let _ = Int32Array.copyAllWithin(view, ~target=1)\n Int32Array.toString(view) == \"10,10,20\"\n ```\n " + "value": "\n `copyAllWithin(typedArray, ~target)` copies values starting at index `0` over the positions beginning at `target`, and returns `typedArray`.\n\n Beware this will *mutate* the typed array.\n\n See [`TypedArray.prototype.copyWithin`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray/copyWithin) on MDN.\n\n ## Examples\n\n ```rescript\n let view = Int32Array.fromArray([10, 20, 30])\n let _ = Int32Array.copyAllWithin(view, ~target=1)\n Int32Array.toString(view) == \"10,10,20\"\n ```\n " }, "insertText": "->Uint8Array.copyAllWithin", "kind": 12, @@ -10686,10 +10686,10 @@ Path } } ], - "detail": "(t, ~target: int, ~start: int, ~end: int=?) => array", + "detail": "(t, ~target: int, ~start: int, ~end: int=?) => t", "documentation": { "kind": "markdown", - "value": "\n `copyWithin(typedArray, ~target, ~start, ~end)` copies the section `[start, end)` onto the range beginning at `target`.\n\n Beware this will *mutate* the typed array.\n\n See [`TypedArray.prototype.copyWithin`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray/copyWithin) on MDN.\n\n ## Examples\n\n ```rescript\n let view = Int32Array.fromArray([1, 2, 3, 4])\n let _ = Int32Array.copyWithin(view, ~target=1, ~start=2, ~end=4)\n Int32Array.toString(view) == \"1,3,4,4\"\n ```\n " + "value": "\n `copyWithin(typedArray, ~target, ~start, ~end)` copies the section `[start, end)` onto the range beginning at `target`, and returns `typedArray`.\n\n Beware this will *mutate* the typed array.\n\n See [`TypedArray.prototype.copyWithin`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray/copyWithin) on MDN.\n\n ## Examples\n\n ```rescript\n let view = Int32Array.fromArray([1, 2, 3, 4])\n let _ = Int32Array.copyWithin(view, ~target=1, ~start=2, ~end=4)\n Int32Array.toString(view) == \"1,3,4,4\"\n ```\n " }, "insertText": "->Uint8Array.copyWithin", "kind": 12, @@ -11610,7 +11610,7 @@ Path "detail": "(t, int => int) => t", "documentation": { "kind": "markdown", - "value": "\n `map(typedArray, f)` returns a new typed array whose elements are produced by applying `f` to each element.\n\n See [`TypedArray.prototype.map`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray/map) on MDN.\n " + "value": "\n `map(typedArray, f)` returns a new typed array of the same kind whose elements are produced by applying `f` to each element.\n\n See [`TypedArray.prototype.map`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray/map) on MDN.\n " }, "insertText": "->Uint8ClampedArray.map", "kind": 12, @@ -11649,10 +11649,10 @@ Path } } ], - "detail": "(t, ~target: int) => array", + "detail": "(t, ~target: int) => t", "documentation": { "kind": "markdown", - "value": "\n `copyAllWithin(typedArray, ~target)` copies values starting at index `0` over the positions beginning at `target`.\n\n Beware this will *mutate* the typed array.\n\n See [`TypedArray.prototype.copyWithin`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray/copyWithin) on MDN.\n\n ## Examples\n\n ```rescript\n let view = Int32Array.fromArray([10, 20, 30])\n let _ = Int32Array.copyAllWithin(view, ~target=1)\n Int32Array.toString(view) == \"10,10,20\"\n ```\n " + "value": "\n `copyAllWithin(typedArray, ~target)` copies values starting at index `0` over the positions beginning at `target`, and returns `typedArray`.\n\n Beware this will *mutate* the typed array.\n\n See [`TypedArray.prototype.copyWithin`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray/copyWithin) on MDN.\n\n ## Examples\n\n ```rescript\n let view = Int32Array.fromArray([10, 20, 30])\n let _ = Int32Array.copyAllWithin(view, ~target=1)\n Int32Array.toString(view) == \"10,10,20\"\n ```\n " }, "insertText": "->Uint8ClampedArray.copyAllWithin", "kind": 12, @@ -11775,10 +11775,10 @@ Path } } ], - "detail": "(t, ~target: int, ~start: int, ~end: int=?) => array", + "detail": "(t, ~target: int, ~start: int, ~end: int=?) => t", "documentation": { "kind": "markdown", - "value": "\n `copyWithin(typedArray, ~target, ~start, ~end)` copies the section `[start, end)` onto the range beginning at `target`.\n\n Beware this will *mutate* the typed array.\n\n See [`TypedArray.prototype.copyWithin`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray/copyWithin) on MDN.\n\n ## Examples\n\n ```rescript\n let view = Int32Array.fromArray([1, 2, 3, 4])\n let _ = Int32Array.copyWithin(view, ~target=1, ~start=2, ~end=4)\n Int32Array.toString(view) == \"1,3,4,4\"\n ```\n " + "value": "\n `copyWithin(typedArray, ~target, ~start, ~end)` copies the section `[start, end)` onto the range beginning at `target`, and returns `typedArray`.\n\n Beware this will *mutate* the typed array.\n\n See [`TypedArray.prototype.copyWithin`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray/copyWithin) on MDN.\n\n ## Examples\n\n ```rescript\n let view = Int32Array.fromArray([1, 2, 3, 4])\n let _ = Int32Array.copyWithin(view, ~target=1, ~start=2, ~end=4)\n Int32Array.toString(view) == \"1,3,4,4\"\n ```\n " }, "insertText": "->Uint8ClampedArray.copyWithin", "kind": 12, diff --git a/tests/build_tests/super_errors/expected/TypedArrayMapElementType.res.expected b/tests/build_tests/super_errors/expected/TypedArrayMapElementType.res.expected new file mode 100644 index 0000000000..3d07fc277d --- /dev/null +++ b/tests/build_tests/super_errors/expected/TypedArrayMapElementType.res.expected @@ -0,0 +1,12 @@ + + We've found a bug for you! + /.../fixtures/TypedArrayMapElementType.res:2:32-46 + + 1 │ let v = (Int32Array.fromArray([1, 2, 3]) :> TypedArray.t) + 2 │ let s = v->TypedArray.map(x => Int.toString(x)) + 3 │ + + This has type: string + But it's expected to have type: int + + You can convert string to int with Int.fromString. \ No newline at end of file diff --git a/tests/build_tests/super_errors/fixtures/TypedArrayMapElementType.res b/tests/build_tests/super_errors/fixtures/TypedArrayMapElementType.res new file mode 100644 index 0000000000..42d0ba2a0d --- /dev/null +++ b/tests/build_tests/super_errors/fixtures/TypedArrayMapElementType.res @@ -0,0 +1,2 @@ +let v = (Int32Array.fromArray([1, 2, 3]) :> TypedArray.t) +let s = v->TypedArray.map(x => Int.toString(x)) diff --git a/tests/tests/src/stdlib/Stdlib_TypedArrayTests.mjs b/tests/tests/src/stdlib/Stdlib_TypedArrayTests.mjs index ea577749d5..5767da01c6 100644 --- a/tests/tests/src/stdlib/Stdlib_TypedArrayTests.mjs +++ b/tests/tests/src/stdlib/Stdlib_TypedArrayTests.mjs @@ -93,6 +93,79 @@ function o(x, map) { return BigInt64Array.from(x, map); } +assertTrue("copyAllWithin returns the typed array it mutated", () => { + let x = new Int32Array([ + 1, + 2, + 3 + ]); + let r = x.copyWithin(1); + if (r === x) { + return r.toString() === "1,1,2"; + } else { + return false; + } +}); + +assertTrue("copyWithin returns the typed array it mutated", () => { + let x = new Int32Array([ + 1, + 2, + 3, + 4 + ]); + let r = x.copyWithin(1, 2, 4); + if (r === x) { + return r.toString() === "1,3,4,4"; + } else { + return false; + } +}); + +assertTrue("TypedArray.copyAllWithin returns the typed array it mutated", () => { + let x = new Int32Array([ + 1, + 2, + 3 + ]); + let r = x.copyWithin(1); + if (r === x) { + return r.toString() === "1,1,2"; + } else { + return false; + } +}); + +assertTrue("TypedArray.copyWithin returns the typed array it mutated", () => { + let x = new Int32Array([ + 1, + 2, + 3, + 4 + ]); + let r = x.copyWithin(1, 2, 4); + if (r === x) { + return r.toString() === "1,3,4,4"; + } else { + return false; + } +}); + +assertTrue("TypedArray.map keeps the element type", () => { + let x = new Int32Array([ + 1, + 2, + 3 + ]); + let r = x.map(v => (v << 1)); + let s = x.map((v, i) => v + i | 0); + if (r.toString() === "2,4,6") { + return s.toString() === "1,3,5"; + } else { + return false; + } +}); + export { eq, num1, diff --git a/tests/tests/src/stdlib/Stdlib_TypedArrayTests.res b/tests/tests/src/stdlib/Stdlib_TypedArrayTests.res index 3c0eff5387..437b0cca76 100644 --- a/tests/tests/src/stdlib/Stdlib_TypedArrayTests.res +++ b/tests/tests/src/stdlib/Stdlib_TypedArrayTests.res @@ -77,3 +77,36 @@ assertTrue("a typed array is a TypedArray.t through a coercion", () => { TypedArray.length(x :> TypedArray.t) == 2 }) let o = (x, map) => BigInt64Array.fromArrayLikeOrIterable(x, ~map) + +// ===== copyWithin and map keep the typed array ===== + +assertTrue("copyAllWithin returns the typed array it mutated", () => { + let x = Int32Array.fromArray([1, 2, 3]) + let r: Int32Array.t = x->Int32Array.copyAllWithin(~target=1) + r === x && Int32Array.toString(r) == "1,1,2" +}) + +assertTrue("copyWithin returns the typed array it mutated", () => { + let x = Int32Array.fromArray([1, 2, 3, 4]) + let r: Int32Array.t = x->Int32Array.copyWithin(~target=1, ~start=2, ~end=4) + r === x && Int32Array.toString(r) == "1,3,4,4" +}) + +assertTrue("TypedArray.copyAllWithin returns the typed array it mutated", () => { + let x = (Int32Array.fromArray([1, 2, 3]) :> TypedArray.t) + let r: TypedArray.t = x->TypedArray.copyAllWithin(~target=1) + r === x && TypedArray.toString(r) == "1,1,2" +}) + +assertTrue("TypedArray.copyWithin returns the typed array it mutated", () => { + let x = (Int32Array.fromArray([1, 2, 3, 4]) :> TypedArray.t) + let r: TypedArray.t = x->TypedArray.copyWithin(~target=1, ~start=2, ~end=4) + r === x && TypedArray.toString(r) == "1,3,4,4" +}) + +assertTrue("TypedArray.map keeps the element type", () => { + let x = (Int32Array.fromArray([1, 2, 3]) :> TypedArray.t) + let r: TypedArray.t = x->TypedArray.map(v => v * 2) + let s: TypedArray.t = x->TypedArray.mapWithIndex((v, i) => v + i) + TypedArray.toString(r) == "2,4,6" && TypedArray.toString(s) == "1,3,5" +})