Skip to content

prettyDOM filterNode argument is called with more args than expected based on type #1360

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

Open
sydneyjodon-wk opened this issue May 15, 2025 · 1 comment

Comments

@sydneyjodon-wk
Copy link

sydneyjodon-wk commented May 15, 2025

Relevant code or config:

prettyDOM(container, undefined, {
  filterNode: (node, unexpectedArg1, unexpectedArg2, shouldBeUndefined) => {
    console.log("arg 1: node - ", node);
    console.log("arg 2: unexpected - ", unexpectedArg1);
    console.log("arg 3: unexpected - ", unexpectedArg2);
    console.log("arg 4: undefined (none) - ", shouldBeUndefined);
    debugger;
    return true;
  },
})

What you did / what happened

The filterNode arg in prettyDOM is typed as having one argument:

filterNode?: (node: Node) => boolean

so I was expecting it to be called with one argument, but it was called with three.

Reproduction:

https://codesandbox.io/p/sandbox/wizardly-shirley-yp96n8?file=%2Fsrc%2F__tests__%2Findex.test.js%3A8%2C27

See in the console that there are three args passed to filterNode:
Image of codesandbox

Problem description:

I think it's being called with three arguments because filterNode is being passed into filter and filter has three args: element, index, and array.

Suggested solution:

Can either the typing of filterNode be updated to indicate that it is called with three arguments or the usage be updated to only call it with the one expected node argument?

Thank you!

Copy link

Uh oh! @sydneyjodon-wk, the image you shared is missing helpful alt text. Check your issue body.

Alt text is an invisible description that helps screen readers describe images to blind or low-vision users. If you are using markdown to display images, add your alt text inside the brackets of the markdown image.

Learn more about alt text at Basic writing and formatting syntax: images on GitHub Docs.

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

No branches or pull requests

1 participant