Closed
Description
Hey,
just tried to add custom field to DirectoryTree object in typescript inside a DirectoryTreeCallback
. The following error occured:
Error:
error TS7053: Element implicitly has an 'any' type because expression of type '"id"' can't be used to index type 'DirectoryTree'.
Property 'id' does not exist on type 'DirectoryTree'.
34 item['id'] = createHash('sha1').update(path).digest('base64');
Example adding custom id
field:
import directoryTree, {
DirectoryTree,
DirectoryTreeCallback,
} from 'directory-tree';
import { createHash } from 'crypto';
const path = 'C:/Users/me/Desktop/a';
const callback: DirectoryTreeCallback = (item: DirectoryTree, path: string) => {
item['id'] = createHash('sha1').update(path).digest('base64');
};
const dirTree: DirectoryTree = directoryTree(path, {}, callback, callback);
console.log(JSON.stringify(dirTree, null, 2));
Fix:
Added [key: string]: any
in to the DirectoryTree
interface at node_modules\directory-tree\index.d.ts
.
I will send you a PR so you can decide if this is a reasonable fix for it.
Best
Lukas
Metadata
Metadata
Assignees
Labels
No labels