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:
ayntee
2021-03-23 14:31:29 +04:00
committed by GitHub
parent 519798d9cd
commit c1a016ca9f
+5 -4
View File
@@ -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) {