99 * Node to calculate a key for.
1010 * @returns {unknown }
1111 * Key to index on.
12+ *
1213 * Can be anything that can be used as a key in a `Map`.
1314 */
1415
@@ -22,20 +23,23 @@ export class Index {
2223 * If `tree` is given, the index is initialized with all nodes, optionally
2324 * filtered by `test`.
2425 *
25- * @param {string| KeyFunction } prop
26+ * @param {string | KeyFunction } prop
2627 * Field (`string`) to look up in each node to find keys or function called
2728 * with each node to calculate keys.
28- * @param {Node } [tree]
29+ * @param {Node | null | undefined } [tree]
2930 * Tree to index.
30- * @param {Test } [test]
31+ * @param {Test | null | undefined } [test]
3132 * `is`-compatible test.
3233 */
3334 constructor ( prop , tree , test ) {
3435 /** @type {Map<unknown, Array<Node>> } */
3536 this . index = new Map ( )
3637 /** @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
3943
4044 if ( tree ) {
4145 visit ( tree , test , ( node ) => {
@@ -49,6 +53,7 @@ export class Index {
4953 *
5054 * @param {unknown } key
5155 * Key to retrieve.
56+ *
5257 * Can be anything that can be used as a key in a `Map`.
5358 * @returns {Array<Node> }
5459 * List of zero or more nodes.
0 commit comments