Skip to content

refactor(collection): ! overrides for unchecked iterator access #10260

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

Closed
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
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
Loading