frontend-collective / frontend-collective/react-sortable-tree

How to use getTreeFromFlatData in typescript?

Open
#524 2 comments 0 reactions 0 assignees View on GitHub
Dominant language
JavaScript
Stars
5k
Forks
914
PR merge metrics
No merged PRs in 30d

Description

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

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
})
```

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.