Skip to content

Commit 85b5c58

Browse files
committed
mark return value of range as readonly to avoid corrupting internal state
1 parent 8f3d8d5 commit 85b5c58

1 file changed

Lines changed: 3 additions & 3 deletions

File tree

packages/range/src/repeat.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ export function repeat<T>(
2222
times: Accessor<number>,
2323
mapFn: (i: number) => T,
2424
options: { fallback?: Accessor<T> } = {},
25-
): Accessor<T[]> {
25+
): Accessor<readonly T[]> {
2626
let prev: readonly T[] = [];
2727
let prevLen: number | undefined;
2828
const disposers: (() => void)[] = [];
@@ -35,9 +35,9 @@ export function repeat<T>(
3535
// Truncate toward zero and force positive
3636
const memoLen = createMemo(() => Math.max(times() | 0, 0));
3737

38-
return function mapLength(): T[] {
38+
return function mapLength(): readonly T[] {
3939
const len = memoLen();
40-
if (len === prevLen) return prev as T[];
40+
if (len === prevLen) return prev;
4141

4242
// Dispose of fallback or unnecessarry elements
4343
if (prevLen === 0) disposers[0]?.();

0 commit comments

Comments
 (0)