-
Notifications
You must be signed in to change notification settings - Fork 0
/
tree-walker.d.ts
28 lines (24 loc) · 1.01 KB
/
tree-walker.d.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
declare namespace BetterTypeScript {
type NodeFilter<T extends BetterTypeScript.NodeFilterMap[keyof BetterTypeScript.NodeFilterMap]> = ((node: T) => number) | { acceptNode(node: T): number; }
interface TreeWalker<T extends BetterTypeScript.NodeFilterMap[keyof BetterTypeScript.NodeFilterMap], R extends Node> {
currentNode: T;
readonly filter: globalThis.NodeFilter | null;
readonly root: R;
readonly whatToShow: number;
firstChild(): T | null;
lastChild(): T | null;
nextNode(): T | null;
nextSibling(): T | null;
parentNode(): T | null;
previousNode(): T | null;
previousSibling(): T | null;
}
interface NodeFilterMap {
[NodeFilter.SHOW_ELEMENT]: Element;
[NodeFilter.SHOW_TEXT]: Text;
[NodeFilter.SHOW_COMMENT]: Comment;
}
}
interface Document {
createTreeWalker<F extends keyof BetterTypeScript.NodeFilterMap, R extends Node>(root: R, whatToShow: F, filter?: BetterTypeScript.NodeFilter<BetterTypeScript.NodeFilterMap[F]>): BetterTypeScript.TreeWalker<BetterTypeScript.NodeFilterMap[F], R>;
}