Skip to content

Commit 7acd483

Browse files
add null safety
1 parent a3ac319 commit 7acd483

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

lib/tree-q/path/p.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,11 @@ interface Item {
2020
function p<T extends Item = Item>(id: string, { data }: { data: T }): string[] {
2121
let path: string[] = [];
2222

23-
function search(node: T, currentPath: string[]): boolean {
23+
function search(node: T | undefined | null, currentPath: string[]): boolean {
24+
if (node == null) {
25+
return false;
26+
}
27+
2428
if (node.id === id) {
2529
path = [...currentPath, node.id];
2630
return true;
@@ -36,6 +40,7 @@ function p<T extends Item = Item>(id: string, { data }: { data: T }): string[] {
3640
return true;
3741
}
3842
}
43+
3944
return false;
4045
}
4146

0 commit comments

Comments
 (0)