I have a function that goes through nodes and places them in a tree:
This is the interface type
interface IDataObj {
children: IDataObj[],
frontmatter : { type: string, title: string, path: string},
name: string,
relativeDirectory: string,
}
in which have my pointer and tree:
let tree: Record<string, IDataObj> = {};
and within my createNode
function:
let ptr: Record<string, IDataObj> = tree;
At a certain point within createNode
have a simple algorithm that decided where to place a node and change the pointer of the tree:
ptr[path[i]] = ptr[path[i]] || node;
ptr[path[i]].children = ptr[path[i]].children || {};
ptr = ptr[path[i]].children; // < this is giving me errors, ptr =
The last line where ptr now points to the chil
Type 'IDataObj[]' is not assignable to type 'Record<string, IDataObj>'.
Index signature is missing in type 'IDataObj[]'.
I'm unaware of how to solve this issue. It seems that fact that I'm using the ability of how loosely typed js is that I arrive at this issue.
question from:
https://stackoverflow.com/questions/66054914/typescript-record-error-when-using-pointer-like-tree 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…