Skip to content

Commit 4c6fe94

Browse files
committed
fixing find type returns
1 parent 0049a20 commit 4c6fe94

2 files changed

Lines changed: 8 additions & 5 deletions

File tree

src/data/Map.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,14 +36,16 @@ export default class DataMap<K = any, V = any> extends Map<K, V> {
3636
* Finds the first key that matches the callback
3737
*/
3838
public findKey(callback: DataMapFilter<K, V, this>) {
39-
return this.find(callback)?.[0];
39+
const entry = this.find(callback);
40+
return Array.isArray(entry) ? entry[0] : undefined;
4041
}
4142

4243
/**
4344
* Finds the first value that matches the callback
4445
*/
4546
public findValue(callback: DataMapFilter<K, V, this>) {
46-
return this.find(callback)?.[1];
47+
const entry = this.find(callback);
48+
return Array.isArray(entry) ? entry[1] : undefined;
4749
}
4850

4951
/**

src/data/Set.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ export default class DataSet<V = any> extends Set<V> {
2727
const values = this.toArray();
2828
for (let i = 0; i < values.length; i++) {
2929
if (callback(values[i], i, this)) {
30-
return [ i, values[i] ];
30+
return [ i, values[i] ] as [number, V];
3131
}
3232
}
3333
return undefined;
@@ -38,14 +38,15 @@ export default class DataSet<V = any> extends Set<V> {
3838
*/
3939
public findIndex(callback: DataSetFilter<V, this>) {
4040
const entry = this.find(callback);
41-
return typeof entry !== 'undefined' ? entry[0] as number : -1;
41+
return Array.isArray(entry) ? entry[0] : undefined;
4242
}
4343

4444
/**
4545
* Finds the first value that matches the callback
4646
*/
4747
public findValue(callback: DataSetFilter<V, this>) {
48-
return this.find(callback)?.[1];
48+
const entry = this.find(callback);
49+
return Array.isArray(entry) ? entry[1] : undefined;
4950
}
5051

5152
/**

0 commit comments

Comments
 (0)