Skip to content

Issue with setting custom field #110

Closed
@ameya730

Description

@ameya730

Hi

I tried to replicate your example of adding a custom field to my directory and I got the below error

TypeError: Cannot set properties of undefined (setting 'id')

Code used

const callback: DirectoryTreeCallback = (
      item: DirectoryTree,
      path: string
    ) => {
      item.custom.id = createHash('sha1').update(path).digest('base64');
    };

    const dirTree: DirectoryTree & { id?: string } = directoryTree(
      unzipTargetPath,
      {},
      callback,
      callback
  );
    
    console.log(JSON.stringify(dirTree, null, 2));

Can you please advice ? I am using Typescript.

Regards,
Ameya

Activity

mihneadb

mihneadb commented on May 10, 2022

@mihneadb
Owner

Hi, you are right, there was an issue with the readme. I pushed an update to it, you should actually define the custom obj yourself.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @mihneadb@ameya730

        Issue actions

          Issue with setting custom field · Issue #110 · mihneadb/node-directory-tree