|
1 | 1 | /** |
2 | | - * @typedef {import('unist').Node} Node |
3 | | - * @typedef {import('unist').Parent} Parent |
| 2 | + * @import {Node, Parent} from 'unist' |
4 | 3 | */ |
5 | 4 |
|
6 | 5 | /** |
|
28 | 27 | * |
29 | 28 | * Note: `Node` is included as it is common but is not indexable. |
30 | 29 | * |
31 | | - * @typedef {Array<Props | TestFunction | string> | Props | TestFunction | string | null | undefined} Test |
| 30 | + * @typedef {Array<Props | TestFunction | string> | ReadonlyArray<Props | TestFunction | string> | Props | TestFunction | string | null | undefined} Test |
32 | 31 | * Check for an arbitrary node. |
33 | 32 | * |
34 | 33 | * @callback TestFunction |
@@ -67,6 +66,8 @@ export const is = |
67 | 66 | // Note: overloads in JSDoc can’t yet use different `@template`s. |
68 | 67 | /** |
69 | 68 | * @type {( |
| 69 | + * (<Condition extends ReadonlyArray<string>>(node: unknown, test: Condition, index?: number | null | undefined, parent?: Parent | null | undefined, context?: unknown) => node is Node & {type: Condition[number]}) & |
| 70 | + * (<Condition extends Array<string>>(node: unknown, test: Condition, index?: number | null | undefined, parent?: Parent | null | undefined, context?: unknown) => node is Node & {type: Condition[number]}) & |
70 | 71 | * (<Condition extends string>(node: unknown, test: Condition, index?: number | null | undefined, parent?: Parent | null | undefined, context?: unknown) => node is Node & {type: Condition}) & |
71 | 72 | * (<Condition extends Props>(node: unknown, test: Condition, index?: number | null | undefined, parent?: Parent | null | undefined, context?: unknown) => node is Node & Condition) & |
72 | 73 | * (<Condition extends TestFunction>(node: unknown, test: Condition, index?: number | null | undefined, parent?: Parent | null | undefined, context?: unknown) => node is Node & Predicate<Condition, Node>) & |
@@ -163,7 +164,11 @@ export const convert = |
163 | 164 | } |
164 | 165 |
|
165 | 166 | if (typeof test === 'object') { |
166 | | - return Array.isArray(test) ? anyFactory(test) : propertiesFactory(test) |
| 167 | + return Array.isArray(test) |
| 168 | + ? anyFactory(test) |
| 169 | + : // Cast because `ReadonlyArray` goes into the above but `isArray` |
| 170 | + // narrows to `Array`. |
| 171 | + propertiesFactory(/** @type {Props} */ (test)) |
167 | 172 | } |
168 | 173 |
|
169 | 174 | if (typeof test === 'string') { |
|
0 commit comments