Skip to content

Commit a2ca171

Browse files
Changes typing definitions for TreeItem to always have children
1 parent 98b53c3 commit a2ca171

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

build/arrayToTree.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ export interface Item {
44
[key: string]: any;
55
}
66
export interface TreeItem {
7-
data?: Item;
7+
data: Item;
88
children: TreeItem[];
99
}
1010
export interface Config {

src/arrayToTree.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ export interface Item {
55
}
66

77
export interface TreeItem {
8-
data?: Item
8+
data: Item
99
children: TreeItem[]
1010
}
1111

@@ -35,7 +35,7 @@ export function arrayToTree (items: Item[], config: Config = { id: 'id', parentI
3535
// look whether item already exists in the lookup table
3636
if (!Object.prototype.hasOwnProperty.call(lookup, itemId)) {
3737
// item is not yet there, so add a preliminary item (its data will be added later)
38-
lookup[itemId] = { children: [] }
38+
lookup[itemId] = { data: null, children: [] }
3939
}
4040

4141
// add the current item's data to the item in the lookup table
@@ -52,7 +52,7 @@ export function arrayToTree (items: Item[], config: Config = { id: 'id', parentI
5252
// look whether the parent already exists in the lookup table
5353
if (!Object.prototype.hasOwnProperty.call(lookup, parentId)) {
5454
// parent is not yet there, so add a preliminary parent (its data will be added later)
55-
lookup[parentId] = { children: [] }
55+
lookup[parentId] = { data: null, children: [] }
5656
}
5757

5858
// add the current item to the parent

0 commit comments

Comments
 (0)