Skip to content

Commit 6baa5db

Browse files
adds type test
1 parent c230075 commit 6baa5db

File tree

2 files changed

+30
-6
lines changed

2 files changed

+30
-6
lines changed

types/index.d.ts

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,19 @@ declare namespace remove {
1717
* Mutate the given tree by removing all nodes that pass test. The tree is walked in preorder (NLR), visiting the node itself, then its head, etc.
1818
*
1919
* @param tree Tree to filter
20-
* @param options Whether to drop parent nodes if they had children, but all their children were filtered out
2120
* @param test is-compatible test (such as a type)
2221
*/
23-
declare function remove(tree: Node, test?: Test<Node>): Node
24-
declare function remove(
22+
export function remove(tree: Node, test?: Test<Node>): Node
23+
/**
24+
*
25+
* Mutate the given tree by removing all nodes that pass test. The tree is walked in preorder (NLR), visiting the node itself, then its head, etc.
26+
*
27+
* @param tree Tree to filter
28+
* @param options Whether to drop parent nodes if they had children, but all their children were filtered out. Default is {cascade: true}
29+
* @param test is-compatible test (such as a type)
30+
*/
31+
export function remove(
2532
tree: Node,
26-
options: remove.RemoveOptions = {cascade: true},
33+
options?: remove.RemoveOptions,
2734
test?: Test<Node>
2835
): Node
29-
30-
export = remove

types/test.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import {remove} from 'uninst-util-remove';
2+
import * as u from 'unist-builder';
3+
4+
let tree = u('root', [
5+
u('leaf', '1'),
6+
u('node', [
7+
u('leaf', '2'),
8+
u('node', [u('leaf', '3'), u('other', '4')]),
9+
u('node', [u('leaf', '5')])
10+
]),
11+
u('leaf', '6')
12+
]);
13+
14+
remove() // $ExpectError
15+
remove('leaf') // $ExpectError
16+
17+
remove(tree)
18+
remove(tree, 'leaf');
19+
remove(tree, {cascade: false}, 'leaf');

0 commit comments

Comments
 (0)