Skip to content

Commit

Permalink
fix(collection): ! overrides for unchecked iterator access
Browse files Browse the repository at this point in the history
The type of Iterator<T>.next().value is currently `any`,
but will soon change to `T | undefined` if noUncheckedIndexedAccess
is set in tsconfig.
  • Loading branch information
Renegade334 committed May 6, 2024
1 parent e673b3c commit ed50e61
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions packages/collection/src/collection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ export class Collection<Key, Value> extends Map<Key, Value> {
if (amount < 0) return this.last(amount * -1);
amount = Math.min(this.size, amount);
const iter = this.values();
return Array.from({ length: amount }, (): Value => iter.next().value);
return Array.from({ length: amount }, (): Value => iter.next().value!);
}

/**
Expand All @@ -104,7 +104,7 @@ export class Collection<Key, Value> extends Map<Key, Value> {
if (amount < 0) return this.lastKey(amount * -1);
amount = Math.min(this.size, amount);
const iter = this.keys();
return Array.from({ length: amount }, (): Key => iter.next().value);
return Array.from({ length: amount }, (): Key => iter.next().value!);
}

/**
Expand Down Expand Up @@ -512,7 +512,7 @@ export class Collection<Key, Value> extends Map<Key, Value> {
if (thisArg !== undefined) fn = fn.bind(thisArg);
const iter = this.entries();
return Array.from({ length: this.size }, (): NewValue => {
const [key, value] = iter.next().value;
const [key, value] = iter.next().value!;
return fn(value, key, this);
});
}
Expand Down Expand Up @@ -626,7 +626,7 @@ export class Collection<Key, Value> extends Map<Key, Value> {
const iterator = this.entries();
if (initialValue === undefined) {
if (this.size === 0) throw new TypeError('Reduce of empty collection with no initial value');
accumulator = iterator.next().value[1];
accumulator = iterator.next().value![1] as unknown as InitialValue;
} else {
accumulator = initialValue;
}
Expand Down

0 comments on commit ed50e61

Please sign in to comment.