Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DirectoryTree - Missing custom field support in typescript interface #104

Merged
merged 4 commits into from Feb 8, 2022

Conversation

lukasrandom
Copy link
Contributor

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.

Already opened an issue here:
#103

Best
Lukas

@mihneadb
Copy link
Owner

@lukasrandom hey, thanks for this! Do you think maybe it'd make more sense to group all of these into some sort of extra object? So at least they are still packed together? Happy to accept the PR otherwise.
Thanks!

@lukasrandom
Copy link
Contributor Author

@mihneadb
Thanks to the feedback :)
New commit adds the "custom" field on the "DirectoryTree" interface to encapsulate additional extra information.

@mihneadb
Copy link
Owner

@lukasrandom thanks! Looks good, with the mention that it appears the indenting was changed from spaces to tabs :S. Please leave it as it was. Oh and it might be worth adding 1-2 words about this new option in the Readme, if you find a place for them.
Thanks!

@lukasrandom
Copy link
Contributor Author

Fixed the formatting issue to stay to the original. Didn't noticed that prettier was changing the formatting.
Added a small readme entry.
Commit: 2e89215

@mihneadb mihneadb merged commit 793462b into mihneadb:master Feb 8, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants