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

TypeError: Cannot read property 'filter' of undefined #21

Open
st-h opened this issue Aug 27, 2020 · 0 comments · May be fixed by #38
Open

TypeError: Cannot read property 'filter' of undefined #21

st-h opened this issue Aug 27, 2020 · 0 comments · May be fixed by #38

Comments

@st-h
Copy link
Contributor

st-h commented Aug 27, 2020

I am trying to define a filter that depends on a sort decorator:

  @sortBy('inviteLinks', 'created', false)
  sortedLinks;

  @filter('sortedLink', link => link.used != null)
  displayedLinks;

However, this leads to the error:
TypeError: Cannot read property 'filter' of undefined

at this function:

function filter(path, fn) {
  return macro(obj => getPath(obj, path).filter(fn));
}

Shouldn't this library be checking if the underlying array is null or undefined before assuming any further method can be called on the object?

Or to put it another way: Is there a way to make this work? I have added a constructor which initialises inviteLinks with an empty array, because I was having the same issue when only using the sortBy decorator. That solved the issue, but as soon as I added the filter decorator, it came back - but this time I have no idea how to work around this, as I think I shouldn't be setting the decorated variable sortedLinks to an empty array, to work around this issue.

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 a pull request may close this issue.

1 participant