9
9
* Node to calculate a key for.
10
10
* @returns {unknown }
11
11
* Key to index on.
12
+ *
12
13
* Can be anything that can be used as a key in a `Map`.
13
14
*/
14
15
@@ -22,20 +23,23 @@ export class Index {
22
23
* If `tree` is given, the index is initialized with all nodes, optionally
23
24
* filtered by `test`.
24
25
*
25
- * @param {string| KeyFunction } prop
26
+ * @param {string | KeyFunction } prop
26
27
* Field (`string`) to look up in each node to find keys or function called
27
28
* with each node to calculate keys.
28
- * @param {Node } [tree]
29
+ * @param {Node | null | undefined } [tree]
29
30
* Tree to index.
30
- * @param {Test } [test]
31
+ * @param {Test | null | undefined } [test]
31
32
* `is`-compatible test.
32
33
*/
33
34
constructor ( prop , tree , test ) {
34
35
/** @type {Map<unknown, Array<Node>> } */
35
36
this . index = new Map ( )
36
37
/** @type {KeyFunction } */
37
- // @ts -expect-error: Looks indexable.
38
- this . key = typeof prop === 'string' ? ( node ) => node [ prop ] : prop
38
+ this . key =
39
+ typeof prop === 'string'
40
+ ? // @ts -expect-error: Looks indexable.
41
+ /** @type {KeyFunction } */ ( ( node ) => node [ prop ] )
42
+ : prop
39
43
40
44
if ( tree ) {
41
45
visit ( tree , test , ( node ) => {
@@ -49,6 +53,7 @@ export class Index {
49
53
*
50
54
* @param {unknown } key
51
55
* Key to retrieve.
56
+ *
52
57
* Can be anything that can be used as a key in a `Map`.
53
58
* @returns {Array<Node> }
54
59
* List of zero or more nodes.
0 commit comments