'How to add a type to the argument using typescript?
Hi i have code like below
type HierarchyQuery = {
Hierarchy: {
data: Array<{
name: string,
description: string,
children: Array<{
name: string,
description: string,
}>
}>
}
}
type HierarchyItem = NonNullable<
HierarchyQuery['Hierarchy']['data'][0]>;
const flattenData = (data: HierarchyItem[] | HierarchyItem) =>
{
const result: HierarchyItem[] = [];
if (isArray(data)) {
data.forEach((item: HierarchyItem) => {
result.push(item);
if (item.children) {
result.push(flattenData(item.children));
//error here
});
}
}
}
but i get error when i call flattenData method on item.children.
argument of type {name: string, description: string, children: {}}[] is not assignable to {name: string, description: string, children: {}}
i am not sure how to fix this error. could someone help me with this. thanks.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
