mirror of
https://github.com/discordeno/discordeno.git
synced 2026-09-17 08:47:22 +00:00
fix(util/collection): .first(), .last(), .random() may return undefined (#680)
* fix(util/collection): .first() may return undefined * fix(util/collection): .random(), .last() may return undefined
This commit is contained in:
@@ -16,16 +16,17 @@ export class Collection<K, V> extends Map<K, V> {
|
||||
return [...this.values()];
|
||||
}
|
||||
|
||||
first(): V {
|
||||
/** Retrieve the value of the first element in this collection */
|
||||
first(): V | undefined {
|
||||
return this.values().next().value;
|
||||
}
|
||||
|
||||
last(): V {
|
||||
last(): V | undefined {
|
||||
return [...this.values()][this.size - 1];
|
||||
}
|
||||
|
||||
random() {
|
||||
return chooseRandom([...this.values()]);
|
||||
random(): V | undefined {
|
||||
return chooseRandom<V>([...this.values()]);
|
||||
}
|
||||
|
||||
find(callback: (value: V, key: K) => boolean) {
|
||||
|
||||
Reference in New Issue
Block a user