Skip to content

How to use getTreeFromFlatData in typescript? #524

@MadLord80

Description

@MadLord80

I don’t understand what the flatData should be?

const testData = [
	{ id: 1, title: 'Chicken', parent: null},
	{ id: 2, title: 'Egg', parent: 1}
]
const tData = getTreeFromFlatData({
	flatData: testData,
	getKey: (node) => node.id,
	getParentKey: (node) => node.parent,
	rootKey: null
})

I got errors in TS:
"Property 'node' is missing in type '{ id: number; title: string; parent: number; }' but required in type 'TreeNode'."

In tree-data-utils.d.ts flatData is described as:
Array<TreeNode & TreePath & {lowerSiblingsCounts: number[]}>

Code works only if use any type:

const tData = getTreeFromFlatData({
	flatData: testData as any,
	getKey: (node: any) => node.id,
	getParentKey: (node: any) => node.parent,
	rootKey: null
})

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions