Giter VIP home page Giter VIP logo

Comments (3)

eranhirsch avatar eranhirsch commented on June 3, 2024 1

It looks like you have a typing issue that isn't related to Remeda directly. I can't help you without seeing how everything is typed, you might be returning undefined in your mapper.

Here's an example that does work:
https://www.typescriptlang.org/play?#code/JYWwDg9gTgLgBAJTgMyhEcBEUCmIcAmAhpgNwBQ5MAnmDnAKIB2MwNcAvHAN7lxxMi+AFxwAzjCjAmAcwr88RYABtREqbIoBfClVr0AwhGUBXEEwDK0VrIDyUAjiicefcTCIwcozAEELBphwAD5YACIMAWRuANY41GqS0nLkOpQAxhBMEnA4LGzAOGKizKw0ANoAui5VFJnZ8GLWTsVwRqbmVrDJ9o5QVTWVuvU5TbBiLggAdCBEYAAUbmNeUGIANG7z3O6eOGtwcdRwWgCUnAB8bvzlV-xw896M+TRnHOf3h5wcXJgAFjjKZQQIIAflyU0E+DgohwU0UKhOGzudwkuy+P38gTgYMwRDE6SCPkc+MwSLu1TxcBGMHIJ2GWVGzQIkymywAQtQHs9Cus4FN+csxHTyEA

from remeda.

eranhirsch avatar eranhirsch commented on June 3, 2024

As far as I remember (without running the code) you probably need to

  1. use as const at the end of the tuple (in the initial "sorts" mapper) so that typescript treats your array as an array of tuples and not an array of arrays. If the typing of sorts isn't correct when you use it in sortBy, Remeda won't be able to infer it. e.g. arr.map((item) => [(e) => { ... }, "asc"] as const)
  2. You don't need that last sorts[0], simply spread the array.

from remeda.

kimwykoff avatar kimwykoff commented on June 3, 2024

@eranhirsch thanks for that. I tried this:

const sorts = sorters.map(sorter =>
      [(x: Entity) => x[sorter.key], sorter.state === ColumnSortingState.Descending ? 'desc' : 'asc'] as const
);
return R.sortBy(entities, ...sorts);

So that compiles, but when I run it, I get:

ERROR TypeError: fn is not a function
    at sortBy.js:40:14
    at Array.sort (<anonymous>)
    at sortBy (sortBy.js:39:46)
    at Module.f2 (_curry2.js:28:14)

Thanks

from remeda.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.