1313 *
1414 * @callback TestFunctionAnything
1515 * @param {Node } node
16- * @param {number } [index]
17- * @param {Parent } [parent]
16+ * @param {number|null|undefined } [index]
17+ * @param {Parent|null|undefined } [parent]
1818 * @returns {boolean|void }
1919 */
2020
2424 * @template {Node} X
2525 * @callback TestFunctionPredicate
2626 * @param {Node } node
27- * @param {number } [index]
28- * @param {Parent } [parent]
27+ * @param {number|null|undefined } [index]
28+ * @param {Parent|null|undefined } [parent]
2929 * @returns {node is X }
3030 */
3131
3232/**
3333 * @callback AssertAnything
3434 * @param {unknown } [node]
35- * @param {number } [index]
36- * @param {Parent } [parent]
35+ * @param {number|null|undefined } [index]
36+ * @param {Parent|null|undefined } [parent]
3737 * @returns {boolean }
3838 */
3939
4343 * @template {Node} Y
4444 * @callback AssertPredicate
4545 * @param {unknown } [node]
46- * @param {number } [index]
47- * @param {Parent } [parent]
46+ * @param {number|null|undefined } [index]
47+ * @param {Parent|null|undefined } [parent]
4848 * @returns {node is Y }
4949 */
5050
@@ -54,8 +54,8 @@ export const is =
5454 * When a `parent` node is known the `index` of node should also be given.
5555 *
5656 * @type {(
57- * (<T extends Node>(node: unknown, test: T['type']|Partial<T>|TestFunctionPredicate<T>|Array.<T['type']|Partial<T>|TestFunctionPredicate<T>>, index?: number, parent?: Parent, context?: unknown) => node is T) &
58- * ((node?: unknown, test?: Test, index?: number, parent?: Parent, context?: unknown) => boolean)
57+ * (<T extends Node>(node: unknown, test: T['type']|Partial<T>|TestFunctionPredicate<T>|Array.<T['type']|Partial<T>|TestFunctionPredicate<T>>, index?: number|null|undefined , parent?: Parent|null|undefined , context?: unknown) => node is T) &
58+ * ((node?: unknown, test?: Test, index?: number|null|undefined , parent?: Parent|null|undefined , context?: unknown) => boolean)
5959 * )}
6060 */
6161 (
@@ -70,8 +70,8 @@ export const is =
7070 * When `function` checks if function passed the node is true.
7171 * When `object`, checks that all keys in test are in node, and that they have (strictly) equal values.
7272 * When `array`, checks any one of the subtests pass.
73- * @param {number } [index] Position of `node` in `parent`
74- * @param {Parent } [parent] Parent of `node`
73+ * @param {number|null|undefined } [index] Position of `node` in `parent`
74+ * @param {Parent|null|undefined } [parent] Parent of `node`
7575 * @param {unknown } [context] Context object to invoke `test` with
7676 * @returns {boolean } Whether test passed and `node` is a `Node` (object with `type` set to non-empty `string`).
7777 */
@@ -104,7 +104,7 @@ export const is =
104104 throw new Error ( 'Expected both parent and index' )
105105 }
106106
107- // @ts -ignore Looks like a node.
107+ // @ts -expect-error Looks like a node.
108108 return node && node . type && typeof node . type === 'string'
109109 ? Boolean ( check . call ( context , node , index , parent ) )
110110 : false
@@ -175,6 +175,8 @@ function anyFactory(tests) {
175175 while ( ++ index < checks . length ) {
176176 if ( checks [ index ] . call ( this , ...parameters ) ) return true
177177 }
178+
179+ return false
178180 }
179181}
180182
@@ -197,7 +199,8 @@ function propsFactory(check) {
197199 let key
198200
199201 for ( key in check ) {
200- if ( node [ key ] !== check [ key ] ) return
202+ // @ts -expect-error: hush, it sure works as an index.
203+ if ( node [ key ] !== check [ key ] ) return false
201204 }
202205
203206 return true
@@ -237,6 +240,7 @@ function castFactory(check) {
237240 * @returns {boolean }
238241 */
239242 function assertion ( ...parameters ) {
243+ // @ts -expect-error: spreading is fine.
240244 return Boolean ( check . call ( this , ...parameters ) )
241245 }
242246}
0 commit comments